Attempting to get Spring internationalization working. I have used classpath:messages basename, created .properties files for languages. They are being corectly copied to web-inf folder and the codes exist within properties file ...
Here is the ide showing everything, please help me. I have copied the set up from another project I have done that works fine. I have tried creating a load of different message files, but its not picking anything up ... pic shows web.xml, spring-servlet.xml, and directory structure.
Edit If I add the bean definition to applicationContext instead of spring-servlet it works .. ?
I'll go for my try:
If the file is located under the WEB-INF/classes
directory, try :
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="WEB-INF/classes/messages" />
</bean>
And the name of the file should be either :
Edit - Final try !
What about this way of writing the configuration, I smell sthg here after your last comment:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
<mvc:interceptors>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
</mvc:interceptors>
Keep your message property files outside the classpath(WEB-INF/classes) and define the bean as below
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/WEB-INF/messages"/>
<property name="cacheSeconds" value="1"/>
As per the doc ReloadableResourceBundleMessageSource provides you benefit of changing the messages on the fly which spring fetches through the cachSeconds. This class differs from ResourceBundleMessageSource only in specifying the resource location.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With