无法解析 Hibernate 验证器消息

发布于 2024-10-15 18:05:57 字数 4091 浏览 2 评论 0原文

由于某种原因,我无法解析 Hibernate 验证器消息。我的 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>

我使用 来解析消息代码。不幸的是,我遇到了以下异常:

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 时,我在 org/hibernate 下找到了 ValidationMessages.properties /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>

但我也遇到了同样的问题。问题是否与语言环境有关?

For some reason, I'm not able to resolve Hibernate Validator messages. I have the following in my 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>

I'm using the <spring:message> to resolve the message code. Unfortunately, I get the following exception:

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)

When I looked inside hibernate-validator-4.1.0-final.jar, I found ValidationMessages.properties under org/hibernate/validator/, so I'm not sure why it's not able to resolve the message.

UPDATE

I copied ValidationMessages.properties into src/main/webapp/WEB-INF/classes/properties and modified my 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>

But I get the same issue. Does the problem have something to do with the locale?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

佼人 2024-10-22 18:05:57

Spring 3.0.x 的初始版本在某些地方有点不稳定,而新的验证内容尤其容易出现这种情况。

我建议升级到当前版本(撰写本文时为 3.0.5,与之前的 3.0.x 版本相比,错误明显减少)。

您还可以通过 SpringSource JIRA 查看是否有影响 3.0.2 和 3.0.3 声音的问题就像你的具体问题一样。

The initial versions of Spring 3.0.x were a bit wobbly in places, and the new Validation stuff was particularly prone to this.

I recommend upgrading to the current release (3.0.5 at time of writing, which is significantly less buggy than previous 3.0.x releases).

You can also have a chug through the SpringSource JIRA to see if any issues affecting 3.0.2 and 3.0.3 sound like your particular problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文