我试图在我的项目上实现国际化,但是我无法解析我的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
,但没有。谢谢。
答案 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 =验证