【发布时间】:2015-09-27 22:03:40
【问题描述】:
我正在使用 Spring MVC+Thymeleaf,当我尝试从 MessageSource 获取消息时出现以下异常:NoSuchMessageException
我的配置:
@Bean(name="messageSource")
public MessageSource messageSource(){
ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
source.setBasename("classpath:i18n/messages");
source.setUseCodeAsDefaultMessage(true);
source.setDefaultEncoding( propWebEncoding );
source.setCacheSeconds(0); /* check the last-modified timestamp */
return source;
}
我的文件位于:
src/main/resources/i18n/messages_es.properties
src/main/resources/i18n/messages_en.properties
我的语言环境是“en”
当我在 HTML (Thymeleaf) 中使用消息“myproperty.example”时,它可以正常工作,但当我尝试在我的@Controller 或@Service 中获取消息时却不行:
@Autowired MessageSource messageSource;
还有
messageSource.getMessage(“myproperty.example”, null, Locale.EN);
它引发了NoSuchMessageException 无法找到的异常……对于语言环境“en”
这一切都是用 maven 配置的,我的 i18n 文件位于以下目标文件夹中:
WEB-INF/classes/i18n/ [files]
我做错了什么?
【问题讨论】:
标签: spring spring-mvc internationalization maven-3 thymeleaf