Skip to content

Instantly share code, notes, and snippets.

@othorizon
Forked from nilandev/MessageConfig.java
Created March 22, 2019 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save othorizon/af03ba70b80fad20e6a439f8c5d4c67b to your computer and use it in GitHub Desktop.
Save othorizon/af03ba70b80fad20e6a439f8c5d4c67b 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment