Created
November 17, 2015 14:39
-
-
Save nilandev/6646a87edf1052aebf75 to your computer and use it in GitHub Desktop.
Spring MVC messageSource configuration via annotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Great job