【发布时间】:2015-05-28 19:08:42
【问题描述】:
我在配置 Spring MessageSource 以忽略我的系统语言环境时遇到问题。当我使用 null 语言环境参数调用 getMessage 时,我希望我的 MessageSource 选择默认属性文件 messages.properties。相反,它选择了messages_en.properties。当我将此属性文件的名称更改为 messages_fr.properties 时,会选择默认属性文件。我的系统语言环境是“en”。所以看起来 MessageSource 忽略了我设置为 false 的 fallbackToSystemLocale 属性。
此行为与 Spring 版本 4.1.4 和 4.1.5 相同。
消息源配置:
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="fallbackToSystemLocale" value="false"></property>
<property name="basenames">
<list>
<value>locale/messages</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8"></property>
</bean>
获取消息:
String message = messageSource.getMessage("user.email.notFound", new Object[] {email}, null);
感谢您的建议!
【问题讨论】:
标签: java spring spring-java-config