I created a Spring Boot web application that uses Thymeleaf as the template engine. I configured the MessageSource
to look for messages in a subfolder:
Because I am using Spring Boot, the MessageSource
is configured with a MessageSourceAutoConfiguration. These settings can be easily changed in the application.properties
file. In my case I had to add the following to this file:
spring.messages.basename=i18n/messages
The way I resolved the i18n messaging was to define the MessagesSource
bean like you. Additionally I had to override the getValidator()
method of the WebMvcConfigurerAdapter
.
@Override
public Validator getValidator() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.setValidationMessageSource( messageSource() );
return validator;
}
After this, it worked for me.
Is there a file messages.properties
(no _de
) present to allow fallback? Does it work? Is your browser set to locale DE_de
?
And add this to your application.properties
file
#messages
spring.messages.basename=i18n/messages
and store the file n the correct folder as specified above.
you don't need messageSource
bean
The message source be relative to classpath:
messageSource.setBasename(" classpath:i18n/messages");
Here is a tutorial I referenced for thymeleaf and spring = http://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html