3

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 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.