Spring MVC:在代码' label.description'下找不到任何消息对于语言环境' en_us'

时间:2016-01-12 02:01:36

标签: java spring spring-mvc internationalization

我试图在我的项目上实现国际化,但是我无法解析我的BaseName,到目前为止这是我的AppConfiguration类方法:

@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new           ReloadableResourceBundleMessageSource();`
    messageSource.setBasename("messages/");
    messageSource.setDefaultEncoding("UTF-8");
    return messageSource;
}

@Bean
public LocaleResolver localeResolver() {
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setDefaultLocale(new Locale("en_US"));
    resolver.setCookieName("myLocaleCookie");
    resolver.setCookieMaxAge(4800);
    return resolver;
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
    LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
    interceptor.setParamName("mylocale");
    registry.addInterceptor(interceptor);
}

这是我的项目结构: Project Structure

任何想法我做错了什么?我也试图将我的baseName更改为classpath:messages,但没有。谢谢。

2 个答案:

答案 0 :(得分:0)

试试这个:

@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename("classpath:/messages/messages");
    messageSource.setDefaultEncoding("UTF-8");
    return messageSource;

}

并将您的en_us.properties重命名为messages_en_us.properties

答案 1 :(得分:0)

只需将此行添加到您的application.properties

即可

spring.messages.basename =验证