出于速度原因,我有一个实用程序类,它根据提供的区域设置加载所有静态数据映射(例如months)。
所以这个实用类看起来像这样:
public static final String GLOBAL_MESSAGES = "globalMessages";
private static Map<Integer,Month> monthsMap;
private ResourceBundle getResourceBundle(Locale locale) {
ResourceBundle rb = ResourceBundle.getBundle(GLOBAL_MESSAGES, locale);
return rb;
}
private Map<Integer,Month> getMonths() {
if(monthsMap == null) {
setMonths();
}
return monthsMap;
}
private void setMonths() {
try {
monthsMap = getFactory().getDAO().getAllMonths();
} catch (SQLException e) {
logger.error(e);
} catch (EmptyResultException e) {
logger.error(e);
}
}
public Map<Integer,Month> getMonths(Locale locale) {
if(locale == null) {
return monthsMap;
} else {
if(this.locale != locale) {
this.locale = locale;
setMonths();
}
}
ResourceBundle rb = getResourceBundle(locale);
Map<Integer,Month> map = new HashMap<Integer, Month>();
for(Month akVO : getMonths().values()) {
try {
akVO.setName(rb.getString(akVO.getName()));
} catch (MissingResourceException e) {
//already done
}
map.put(akVO.getId(), akVO);
}
return map;
}
文件globalMessages.properties(globalMessages\u en\u US.properties,…)直接位于源程序包中
资源
. 在Tomcat上部署时,文件夹中有
WEB-INF/类
现在问题来了。
在这个应用程序中工作时,一切都正常
. 但是我有另一个应用程序,它通过restapi(JAX-RS)连接到这个应用程序。提出请求时
App/rest/months.xml
我得到以下错误:
java.util.MissingResourceException: Can't find bundle for base name globalMessages, locale en_us