- resources/message中添加hello.properties配置
user.name=UserName {0}
- resources/message中添加hello_zh_CN.properties配置
user.name=用户名 {0}
- 添加单元测试
@Slf4j public class MessageSourceTest {@Testpublic void message(){Locale locale = LocaleContextHolder.getLocale();String errorMessage = "message/hello";ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource();bundleMessageSource.setBasenames(errorMessage);bundleMessageSource.setDefaultEncoding("UTF-8");String message = bundleMessageSource.getMessage("user.name", new Object[]{"测试"}, locale);log.info("message : {}", message);} }