解析validation.xml时出错:null

时间:2013-06-17 16:18:33

标签: hibernate xml-parsing bean-validation

在尝试使用Bean Validation(JSR-303)自定义约束时,使用注释和XML配置为described here,我在日志中收到以下错误,并忽略约束:

<Error> <org.hibernate.validator.xml.ValidationXmlParser> <BEA-000000> <Error parsing validation.xml: null>

我使用Weblogic 12.1.1作为应用程序服务器,我的应用程序部署为war文件。

validation.xml constraint-mapping.xml 文件都放在WEB-INF / classes / META-INF下。

有人知道可能导致这种情况的原因吗?这是一个依赖或冲突的库问题吗?

这是我的 validation.xml

<validation-config xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration">
     <default-provider>org.hibernate.validator.HibernateValidator</default-provider>
     <constraint-mapping>META-INF/constraint-mapping.xml</constraint-mapping>
</validation-config>

我的 constraint-mapping.xml

<constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"
                     xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
<constraint-definition annotation="foo.CustomConstraint">
    <validated-by include-existing-validators="true">
        <value>foo.CustomConstraintValidator</value>
    </validated-by>
</constraint-definition>
</constraint-mappings>

提前致谢,

迪米瑞斯

更新


按照Gunnar的建议,我做了以下事情:

  • 使用版本4.3.1覆盖Weblogic的默认hibernate验证器(4.1.0)
  • 调试了ValidationXmlParser类。

这给了我以下例外:

javax.xml.bind.UnmarshalException
 - with linked exception:
[Exception [EclipseLink-25004] (Eclipse Persistence Services - 2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: An error occurred unmarshalling the document
Internal Exception: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 96;
SchemaLocation: schemaLocation value =
'http://jboss.org/xml/ns/javax/validation/configuration' must have even number of URI's.]

为了解决这个问题,我更新了 validation.xml 中的 xsi:schemaLocation ,如下所示:

xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration
                    http://jboss.org/xml/ns/javax/validation/configuration/validation-configuration-1.0.xsd"

此更改修复了上一个错误,但我的注释仍然被忽略。我在这里想念什么?

1 个答案:

答案 0 :(得分:0)

您的XML文件似乎不完整(有关完整示例,请参阅here):

  • validation.xml缺少结束</validation-config>代码
  • constraint-maping.xml必须以<constraint-mappings>作为根元素

AFAIK WLS 12.1.1仍然使用Hibernate Validator 4.1.0,不幸的是吞下了在解组JAXBException期间引发的任何validation.xml。如果问题仍然存在,我建议使用Hibernate Validator 4.1.0源调试问题并检查ValidationXmlParser:L216中捕获的JAXBException。在以后的HV版本中,也会传播根异常。