无法解析Hibernate Validator消息

时间:2011-01-31 16:21:22

标签: java spring spring-mvc hibernate-validator

由于某种原因,我无法解析Hibernate Validator消息。我的applicationContext.xml

中有以下内容
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>properties.message</value>
            <value>org.hibernate.validator.ValidationMessages</value>
        </list>
    </property>
</bean>

我正在使用<spring:message>来解析消息代码。不幸的是,我得到以下例外:

javax.servlet.jsp.JspTagException: No message found under code 'org.hibernate.validator.constraints.NotBlank.message' for locale 'en_US'.
    org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:184)
    org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
    org.apache.jsp.tag.web.generate_002dvalidation_tag._jspx_meth_spring_005fmessage_005f0(generate_002dvalidation_tag.java:645)
    org.apache.jsp.tag.web.generate_002dvalidation_tag._jspx_meth_c_005fset_005f4(generate_002dvalidation_tag.java:611)
    org.apache.jsp.tag.web.generate_002dvalidation_tag._jspx_meth_c_005fif_005f1(generate_002dvalidation_tag.java:569)
    org.apache.jsp.tag.web.generate_002dvalidation_tag._jspx_meth_c_005fforEach_005f2(generate_002dvalidation_tag.java:505)
    org.apache.jsp.tag.web.generate_002dvalidation_tag._jspx_meth_c_005fforEach_005f1(generate_002dvalidation_tag.java:417)
    org.apache.jsp.tag.web.generate_002dvalidation_tag._jspx_meth_c_005fforEach_005f0(generate_002dvalidation_tag.java:328)
    org.apache.jsp.tag.web.generate_002dvalidation_tag._jspx_meth_c_005fif_005f0(generate_002dvalidation_tag.java:197)
    org.apache.jsp.tag.web.generate_002dvalidation_tag.doTag(generate_002dvalidation_tag.java:109)
    org.apache.jsp.WEB_002dINF.jsp.starship.create_jsp._jspx_meth_regula_005fgenerate_002dvalidation_005f0(create_jsp.java:1027)
    org.apache.jsp.WEB_002dINF.jsp.starship.create_jsp._jspService(create_jsp.java:598)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1063)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:801)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

当我查看hibernate-validator-4.1.0-final.jar时,我在ValidationMessages.properties下找到了org/hibernate/validator/,所以我不确定为什么它无法解析该消息。

更新

我将ValidationMessages.properties复制到src/main/webapp/WEB-INF/classes/properties并修改了我的applicationContext.xml

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>properties.message</value>
            <value>properties.ValidationMessages</value>
        </list>
    </property>
</bean>

但我得到同样的问题。该问题是否与区域设置有关?

1 个答案:

答案 0 :(得分:2)

Spring 3.0.x的初始版本在某些地方有点不稳定,新的Validation内容特别容易出现这种情况。

我建议升级到当前版本(在编写本文时为3.0.5,这比以前的3.0.x版本要小得多)。

您还可以通过SpringSource JIRA查看是否有任何影响3.0.2和3.0.3的问题听起来像您的特定问题。