我的计划是使用messages.properties文件的值更新servlet-context.xml中的缺省语言环境值。验证了其他StackOverflow问题和其他链接,但没有成功。
servlet-context.xml是,
<context:property-placeholder location="C:\\Users\\Mahesh\\Downloads\\SpringInternalization\\src\\main\\resources\\messages.properties" />
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<!-- <property name="basename" value="classpath:messages" /> -->
<property name="basenames">
<list>
<value>classpath:messages</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" >
<value>${property.language}</value>
</property>
</bean>
<!--
<mvc:interceptors>
<bean
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
</mvc:interceptors>
-->
<context:component-scan base-package="com.jocata.spring" />
请帮助这些家伙。提前致谢。 尝试以下,
Use property file's property in spring mvc configuration servlet xml
答案 0 :(得分:1)
您的语言文件名是什么? 为什么需要指定属性文件的绝对路径?
试试这个
<context:property-placeholder location="classpath:messages.properties" />
或者在文件路径中使用正斜杠
<context:property-placeholder location="file:C:/Users/Mahesh/Downloads/SpringInternalization/src/main/resources/messages.properties" />