Can someone please help me? I'm trying to follow this post(https://www.javadevjournal.com/spring-boot/spring-custom-validation-message-source/), to make custom validation messages. I was confused in part 5, which is defining the properties of the file. Do I have to create a file exactly with this nomenclature "messages_ {locale} .properties"? Or do I put the messages inside aplication.properties?
1 Answer
Firstly, you have to configure messages source. Following the tutorial you have to implement bean like this:
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("classpath:messages");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
Where classpath:messages is a base name of messages files placed inside /resource directory. Therefore, you must follow the convention of creating files like messages_{locale}.properties where locale means a specific language tag.
For example, assuming you want to handle english and spanish messages, you must create following files: messages_en.properties and messages_es.properties.
1 Comment
GobsRuiz
Thank you very much