【发布时间】:2013-03-05 13:09:57
【问题描述】:
如何根据我的语言正确获取 spring 消息验证,作为回报,我得到的是默认休眠验证器,而不是注释 @NotEmpt 中定义的消息。
@Entity
public class News {
@Id
private Integer idNews;
@NotEmpty(message = "{news.title.error}")
@Column
private String title;
........
}
在我的配置中:
<!-- locale change using a cookie -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" >
<property name="defaultLocale" value="pt" />
</bean>
<!-- Access resource bundles with the specified basename -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>/WEB-INF/i18n/messages</value>
<value>/WEB-INF/i18n/validation</value>
</list>
</property>
</bean>
<!-- JSR-303 -->
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="validationMessageSource" ref="messageSource"/>
</bean>
【问题讨论】:
-
您是否有一个包含正确密钥的
validation_pt.properties文件? -
是的,在这种情况下使用 2 个语言环境 en 和 pt,默认语言环境是 pt。
-
我的结果消息是 {news.title.error} 在视图中:
<form:errors path="*" cssClass="alert alert-error" element="div"/> -
是的文件是正确的。
标签: spring hibernate internationalization