-
-
Save othorizon/af03ba70b80fad20e6a439f8c5d4c67b 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