英文:
Can't find bundle for base name Warn
问题
ResourceBundle [classpath:/org/springframework/security/messages] 未找到用于 MessageSource 的资源包: 无法找到基础名称为 classpath:/org/springframework/security/messages 的资源包,区域设置为 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;
}
英文:
ResourceBundle [classpath:/org/springframework/security/messages] not found for MessageSource: Can't find bundle for base name classpath:/org/springframework/security/messages, locale ru
I can't find any solution for setting internationalization in Java
This is how my code looks like
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
得分: 1
以下是翻译好的内容:
基本名称是相对于类路径根目录的,无需编写,参见1.15.1. 使用MessageSource
进行国际化:
<beans>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>format</value>
<value>exceptions</value>
<value>windows</value>
</list>
</property>
</bean>
</beans>
该示例假设在类路径中定义了名为 format
、exceptions
和 windows
的三个资源包。解析消息的任何请求都是通过ResourceBundle
对象以JDK标准方式处理的。
您修改后的代码:
@Bean
@Primary
public MessageSource messageSource() {
ResourceBundleMessageSource rs = new ResourceBundleMessageSource();
rs.setBasenames("org/springframework/security/messages");
rs.setDefaultEncoding("UTF-8");
rs.setUseCodeAsDefaultMessage(true);
return rs;
}
英文:
The basenames are relative to the root of the class path, you don't have to write it, see 1.15.1. Internationalization using MessageSource
:
> <!--language: xml -->
>
> <beans>
> <bean id="messageSource"
> class="org.springframework.context.support.ResourceBundleMessageSource">
> <property name="basenames">
> <list>
> <value>format</value>
> <value>exceptions</value>
> <value>windows</value>
> </list>
> </property>
> </bean>
> </beans>
>
> The example assumes that you have three resource bundles called format
, exceptions
and windows
defined in your classpath. Any request to resolve a message is handled in the JDK-standard way of resolving messages through ResourceBundle
objects.
Your modified code:
<!-- language: java -->
@Bean
@Primary
public MessageSource messageSource() {
ResourceBundleMessageSource rs = new ResourceBundleMessageSource();
rs.setBasenames("org/springframework/security/messages");
rs.setDefaultEncoding("UTF-8");
rs.setUseCodeAsDefaultMessage(true);
return rs;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论