spring boot国际化类ReloadableResourceBundleMessageSource
spring boot国际化使ReloadableResourceBundleMessageSource设置basenames并返回messagesource
@Configuration public class I18nConfig { @Bean(name = "messageSource") public ReloadableResourceBundleMessageSource messageSource() { ReloadableResourceBundleMessageSource messageBundle = new ReloadableResourceBundleMessageSource(); messageBundle.setBasename("classpath:messages/messages"); messageBundle.setDefaultEncoding("UTF-8"); return messageBundle; } }
接着直接使用:
代码调用:
@Autowired @Qualifier("messageSource") private MessageSource messageSource; //下面在方法种使用 messageSource.getMessage("test", new Object[], SIMPLIFIED_CHINESE);