[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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s