Madhesh Madhesh - 1 year ago 72
Java Question

spring3 internationalization not working properly

I am newbie to spring.I used spring internationalization in my project.Below is my configuration

<bean id="messageSource"
<property name="basename" value="WEB-INF/properties/messages" />
<property name="defaultEncoding" value="UTF-8" />

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en"/>

<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />

<bean id="handlerMapping"
<property name="interceptors">
<ref bean="localeChangeInterceptor" />

In the properties folder i have three files.




i display the message using
<spring:message code="label.username" />
this tag.

But this one always prints the value from
It always prints user.

even i give the url like below


why values not taken from the files messages_en and messages_es

Any help will be greatly appreciated!!!

Answer Source

When using <mvc:annotation-driven /> configuring the DefaultAnnotationHandlerMapping will not work. You should use the <mvc:interceptors /> element to register the interceptors.

    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang" />

Next to that it doesn't work in newer versions of Spring (everything after 2.5) doesn't use the DefaultAnnotationHandlerMapping anymore in case of <mvc:annotation-driven />.