Caused by: org.springframework.context.NoSuchMessageException: No message found under code
Solution 1
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 :
- messages.properties
- messages_en.properties
- messages_en_GB.properties
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>
Solution 2
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.
NimChimpsky
side hustle : metriculous.network Spring is too bloated, I created my own web app framework Infrequent tweets What if programming languages were methods to eat an orange?
Updated on April 22, 2020Comments
-
NimChimpsky about 4 years
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 .. ?