我想添加國際化到我的Spring MVC應用程序。我知道它可以是一個複製問題,但我已經嘗試了從stackoverflow和谷歌的所有解決方案,但仍然無法工作。我會詳細解釋。這裏是Spring MVC 3 localeChangeInterceptor
的web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
根的context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<!-- Localization Start -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="defaultEncoding" value="UTF-8"/>
<property name="basenames">
<list>
<value>/WEB-INF/messages</value>
</list>
</property>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="tr" />
</bean>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
<!-- Localization End -->
</beans>
我有messages_en.properties和messages_tr.properties文件。他們工作正常,因爲當我將defaultLocale更改爲en或tr時,我從屬性文件中獲得了真正的標籤。 但問題是,當我從瀏覽器?lang=tr or ?lang=en
嘗試沒有什麼改變。
感謝您的關注!
檢查每個配置只有一個「HandlerMapping」。 – aim