开发者

Spring 3.0 localization not working in tomcat, only from jetty locally

开发者 https://www.devze.com 2023-03-07 12:46 出处:网络
I am struggling with getting the localization to work when I deploy my app to tomcat. I\'ve got this setup in my applicationContext.xml:

I am struggling with getting the localization to work when I deploy my app to tomcat. I've got this setup in my applicationContext.xml:

<!-- Configures Handler Interceptors -->    
<mvc:interceptors>
    <!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de -->
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" >
        <property name="paramName" value="locale" />
    </bean>
</mvc:interceptors>

<!-- Saves a locale change using a cookie -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
    <property name="defaultLocale" value="no" />
</bean>

<!-- Application Message Bundle -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="useCodeAsDefaultMessage" value="true" />
    <property name="basename" value="classpath:language" />
    <property name="cacheSeconds" value="0" />
</bean>

Now, the localization works just fine when I run it from Jetty locally. It's when I run the app from tomcat that it consequentially displays the language from the language_en.properties file, not my default file language.properties. And when I try to change the locale with ?locale=no (norwegian) nothing happends to the language on the site, but the log shows that the locale is actually changed to "no".

Has someone got any solutions or sug开发者_JS百科gestion to solution to this, or maybe an alternative way of setting up the localization. I am open for anything and everything.


Try

classpath*:language

ie, search ALL classpaths. Depending on where you are deploying your resource bundles, they may end up in different places in the classloader hierarchy in tomcat and jetty.


FINALLY! I solved it!

I had to set the JvmOptions: 
-Duser.language=no 
-Duser.region=NO

in order for tomcat to use the language.properties and not the language_en.properties file. And for some strange reason it now also works when setting the locale (?locale=en) to english too.

0

精彩评论

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