您好,我正在尝试在我的 Spring MVC Web 应用程序中配置消息源。
我目前已经让它与 ReloadableResourceBundleMessageSource 一起运行,但我无法让它与 ResourceBundleMessageSource 一起运行。我更愿意使用 ResourceBundleMessageSource,因为我不需要重新加载功能,而且 ResourceBundleMessageSource 的效率稍微高一些。
在我的 rootApplicationContext 中,我定义了如下 bean。
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/resources/locale/messages" />
<property name="defaultEncoding" value="UTF-8"/>
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
这很好..
但是一旦我变成
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="/resources/locale/messages" />
<property name="defaultEncoding" value="UTF-8"/>
</bean>
应用程序异常中断:
12:35:57,433 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SpringJAXWS].[jsp]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet jsp threw exception: org.apache.tiles.util.TilesIOException: JSPException including path '/jsp/views/layout/top.jsp'. at org.apache.tiles.servlet.context.ServletUtil.wrapServletException(ServletUtil.java:241) [tiles-servlet-2.2.2.jar:2.2.2] at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:105) [tiles-jsp-2.2.2.jar:2.2.2]
帮助!
整个项目代码在 GITHUB 上可用
https://github.com/localghost8080/JaxWS
这里是所有感兴趣的人的完整堆栈跟踪。
https://github.com/localghost8080/JaxWS/blob/master/ResourceBundleException.txt
最佳答案
ResourceBundleMessageSource 使用不同的格式来传递 basename 值
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="resources.locale.messages" />
<property name="defaultEncoding" value="UTF-8"/>
关于java - Spring ReloadableResourceBundleMessageSource VS ResourceBundleMessageSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20159669/