Spring 3.0本地化在tomcat中不起作用,只能从本地码头工作
当我将应用程序部署到 tomcat 时,我正在努力使本地化正常工作。 我在 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>
现在,当我从 Jetty 本地运行它时,本地化工作得很好。 当我从 tomcat 运行应用程序时,它会显示 language_en.properties 文件中的语言,而不是我的默认文件 language.properties。当我尝试使用 ?locale=no (挪威语)更改区域设置时,网站上的语言没有发生任何变化,但日志显示区域设置实际上已更改为“no”。
有人有任何解决方案或建议来解决这个问题,或者可能是设置本地化的替代方法。我对任何事情都持开放态度。
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 suggestion to solution to this, or maybe an alternative way of setting up the localization. I am open for anything and everything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
类路径*:语言
,即搜索所有类路径。根据您部署资源包的位置,它们最终可能位于 tomcat 和 jetty 的类加载器层次结构中的不同位置。
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.
最后!我解决了!
为了让 tomcat 使用
language.properties
而不是language_en.properties
文件。由于某些奇怪的原因,现在将语言环境 (?locale=en) 设置为英语时也可以工作。
FINALLY! I solved it!
in order for tomcat to use the
language.properties
and not thelanguage_en.properties
file.And for some strange reason it now also works when setting the locale (?locale=en) to english too.