【问题标题】:Spring MVC i18n Hibernate ValidationSpring MVC i18n 休眠验证
【发布时间】: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} 在视图中:&lt;form:errors path="*" cssClass="alert alert-error" element="div"/&gt;
  • 是的文件是正确的。

标签: spring hibernate internationalization


【解决方案1】:

您的问题也许可以像这个问题一样解决: https://jira.springsource.org/browse/SPR-8658?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

重点是

change <mvc:annotation-driven /> to <mvc:annotation-driven validator="validator"/>

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2019-03-20
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2011-04-30
    • 2023-03-08
    • 2014-02-02
    • 1970-01-01
    相关资源
    最近更新 更多