Skip to content

Instantly share code, notes, and snippets.

@nilandev
Created November 17, 2015 14:39
Show Gist options
  • Save nilandev/6646a87edf1052aebf75 to your computer and use it in GitHub Desktop.
Save nilandev/6646a87edf1052aebf75 to your computer and use it in GitHub Desktop.
Spring MVC messageSource configuration via annotation
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
@Configuration
public class MessageConfig {
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath:message.properties", "classpath:ValidationMessages.properties");
// if true, the key of the message will be displayed if the key is not
// found, instead of throwing a NoSuchMessageException
messageSource.setUseCodeAsDefaultMessage(true);
messageSource.setDefaultEncoding("UTF-8");
// # -1 : never reload, 0 always reload
messageSource.setCacheSeconds(0);
return messageSource;
}
}
@kayamuhendiss
Copy link

kayamuhendiss commented Feb 27, 2019

Great job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment