0

Reading documentation: https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#section-mapping-xml-constraints

I removed one long bean definition for brevity, then source looks like below. When executed, I get: Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'constraint-mappings'. Great, so there should be something wrong with schema or xml file.

But what. I never actually understood all that weird definition of namespaces. So first 3 http URLs leads nowhere and they probably serve some higher purpose, while the last one ending in xsd does exist and does define constraint-mappings element. And whole document is, according to Intellij IDEA valid, which it is I believe. I if I try to corrupt it, then IntellijIDEA sees it. So I'd presume that it actually is valid. So why on earth spring produces given error on startup???

validation.xml file:

<constraint-mappings
    xmlns="http://xmlns.jcp.org/xml/ns/validation/mapping"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/validation/mapping
            http://xmlns.jcp.org/xml/ns/validation/mapping/validation-mapping-2.0.xsd"
    version="2.0">

  <default-package>org.hibernate.validator.referenceguide.chapter05</default-package>
  <bean class="RentalCar">
    <class ignore-annotations="true">
      <group-sequence>
        <value>RentalCar</value>
        <value>CarChecks</value>
      </group-sequence>
    </class>
  </bean>
  <constraint-definition annotation="org.mycompany.CheckCase">
    <validated-by include-existing-validators="false">
      <value>org.mycompany.CheckCaseValidator</value>
    </validated-by>
  </constraint-definition>
</constraint-mappings>
Martin Mucha
  • 2,385
  • 1
  • 29
  • 49

1 Answers1

1

validation.xml file is dedicated to provide the configurations for validation factory. You could configure clock provider, additional value extractors etc. Also you can reference constraint-mapping files in there (the one that you have in your post). Here's a part of an example from the documentation:

<validation-config
        xmlns="http://xmlns.jcp.org/xml/ns/validation/configuration"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/validation/configuration
            http://xmlns.jcp.org/xml/ns/validation/configuration/validation-configuration-2.0.xsd"
        version="2.0">

    <default-provider>com.acme.ValidationProvider</default-provider>

    <message-interpolator>com.acme.MessageInterpolator</message-interpolator>
    <traversable-resolver>com.acme.TraversableResolver</traversable-resolver>
    <constraint-validator-factory>
        com.acme.ConstraintValidatorFactory
    </constraint-validator-factory>
    <parameter-name-provider>com.acme.ParameterNameProvider</parameter-name-provider>
    <clock-provider>com.acme.ClockProvider</clock-provider>

    <value-extractor>com.acme.ContainerValueExtractor</value-extractor>

    <constraint-mapping>META-INF/validation/constraints-car.xml</constraint-mapping>

    <property name="hibernate.validator.fail_fast">false</property>
</validation-config>

Hence validation.xml is expected to have validation-config element. That's most likely why you get that error.

mark_o
  • 2,052
  • 1
  • 12
  • 18