开发者

Spring 2.5 localeChangeInterceptor somehow did not work

I'm trying to use localeChangeInterceptor to load different language depends on the locale, but somehow it never changes. It is always the defaultLocale.

Here is how I set up the beans

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

<bean id="localeChangeInterceptor"
    class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" va开发者_运维问答lue="language" />
</bean>

<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" >
    <property name="interceptors">
       <list>
        <ref bean="localeChangeInterceptor" />
       </list>
    </property>
</bean>

<!-- Register the message.properties -->
<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="message" />
</bean>

The URL I use to access different locale is:

    http://localhost:8080/something/message/login?language=zh_CN

I think I have a reason why it isn't working, it is because I'm use annotation for URL mapping. So is there another way to setup the localeChangeInterceptor with annotation?


So after I notice the reason why it is not working is because I'm using annotation for URL mapping, the rest of it is simple.

Instead of using ControllerClassNameHandlerMapping, I should use DefaultAnnotationHandlerMapping. And this is how to set it up.

<bean id="annotationMapper" 
     class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="interceptors">
        <list>
            <ref bean="localeChangeInterceptor"/>
        </list>
    </property>
</bean>

Cheers!


As you have set the paramName manually, you should use the following url: http://localhost:8080/something/message/login?language=zh_CN

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜