我使用Spring ResourceBundleMessageSource进行国际化。在视图表单中,我使用fmt:message
表单字段标签。在字段值不正确的验证器中,我必须拒绝具有相应表单字段标签和字段的字段。错误信息。
例如<fmt:message key"abc" /> <form:input name="xyz">
错误信息是:“abc的值不正确”。
在验证器中我必须说 -
`errors.rejectValue("xyz", "error.message", new Object[] {getMessage("message.abc")})`
spring config:
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="MySource" />
</bean>
在getMessage
我正在使用MessageSourceAccesor
来读取资源文件中的消息。
我的资源文件名是MySource.properties
,我的资源文件夹中没有其他语言特定文件,我也可以在jsp视图中读取此文件中的标签,但是我得到了异常({{1当我试图从验证器访问它时,对于语言环境中的abc。
简短的问题是如何指示spring资源使用默认属性文件(没有后缀的文件名)在没有提供语言资源文件时搜索消息?
任何指针都有助于前进。
答案 0 :(得分:1)
我遇到了同样的问题。在检查spring mvc的文档后,我的是版本4.1.1, ResourceBundleMessageSource 有&#34; basenames &#34;作为财产而不是&#34; basename &#34;
private String[] basenames = new String[0];
更新在spring web app上下文中配置的ResourceBundleMessageSource bean的属性名称,使其工作:D
<property name="basenames" value="messages"></property>
我无法发布截图,因为我需要10分,而且我是新手:D
答案 1 :(得分:0)
我假设你使用的是Spring MVC,
您是否在应用程序上下文文件中配置了Spring Resource bundle
示例
<beans:bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:property name="basename" value="classpath:messages" />
<beans:property name="defaultEncoding" value="UTF-8" />
</beans:bean>
此链接通过演示详细说明 Spring Resource bundle with ResourceBundleMessageSource example
如果有帮助,请为帖子评分。