[Java] – Spring – How to configure a messages file ?

The file with messages will be : messages.properties

Implement the method in AppWebConfiguration.class:

        @Bean
        public MessageSource messageSource() {
            ReloadableResourceBundleMessageSource messageSource =
                    new ReloadableResourceBundleMessageSource();

            messageSource.setBasename("/WEB-INF/messages");
            messageSource.setDefaultEncoding("UTF-8");
            messageSource.setCacheSeconds(1);

            return messageSource;
        }

Example of messages.file :

field.required = Field Requeried
field.required.product.title = Title of product is a requeried field

Leave a comment