This is my messageResource declaration
In general such issue appears not because of non-existence locale, but because MessageBundle
is configured improperly. In your case you seem to need to remove "/" in your basename.
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
p:basename="/WEB-INF/messages" />
Why it is so:
If you have messages.properties
and messages_en.properties
bundle, then bundle name is messages
. If you have them in the WEB-INF
folder, then basename is /WEB-INF/messages
, i.e. according to /path/to/bundle/bundlename
. If you have messages.properties
within /WEB-INF/messages
folder, then corresponding basename is /WEB-INF/messages/messages
.
You can specify in Spring boot application.properties too
# INTERNATIONALIZATION
spring.messages.basename=i18n/messages
spring.messages.encoding=UTF-8
You can add some code in application.properties:
spring.messages.always-use-message-format=false
spring.messages.basename=messages
spring.messages.cache-seconds=-1
spring.messages.encoding=UTF-8
spring.messages.fallback-to-system-locale=true
For spring boot folder ressources you need to add name of Bean:
@Bean(name="messageSource")
public ResourceBundleMessageSource bundleMessageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
return messageSource;
}
For spring boot you need something like this:
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("/WEB-INF/classes/messages");
return messageSource;
}
By default maven assumes to find such resource bundle message source under
src/main/resources
. By moving all the necessary folders under the location and also making sure we have the following code in the context
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename"><value>messages</value></property>
</bean>