找不到messagesource的resourcebundle[classpath:/org/springframework/security/messages]source:找不到基名称classpath:/org/springframework/security/messages的bundle,locale ru我找不到任何在java中设置国际化的解决方案
我的代码就是这样的
public static final Locale defaultLocale = new Locale("ru");
public LocaleConfig() {
}
@Bean
public LocaleResolver localeResolver() {
return new FixedLocaleResolver(defaultLocale);
}
@Bean
@Primary
public MessageSource messageSource() {
ResourceBundleMessageSource rs = new ResourceBundleMessageSource();
rs.setBasenames("classpath:i18n/messages");
rs.setBasenames("classpath:/org/springframework/security/messages");
rs.setDefaultEncoding("UTF-8");
rs.setUseCodeAsDefaultMessage(true);
return rs;
}
@Bean
@Primary
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName("lang");
return localeChangeInterceptor;
}
1条答案
按热度按时间2jcobegt1#
基名相对于类路径的根,您不必编写它,请参见1.15.1。国际化使用
MessageSource
:该示例假设您有三个名为
format
,exceptions
以及windows
在类路径中定义。解析消息的任何请求都是通过jdk解析消息的标准方式处理的ResourceBundle
物体。修改后的代码: