2
votes

I have a simple restful web service that uses Bean Validation 1.1 (and Hibernate Validator 5.1.3 as the implementation) and I'm deploying it on JBoss EAP 6.4.0. Since JBoss 6.4 comes bundled with Bean Validation 1.0 and its implementation library (Hibernate Validator 4.3.2), there is a conflict and none of service calls work. Below is the error that I get:

java.lang.NoSuchMethodError: javax.validation.Validator.forExecutables()Ljavax/validation/executable/ExecutableValidator;
    org.apache.cxf.validation.BeanValidationProvider.getExecutableValidator(BeanValidationProvider.java:153)
    org.apache.cxf.validation.BeanValidationProvider.validateReturnValue(BeanValidationProvider.java:124)
    org.apache.cxf.validation.BeanValidationOutInterceptor.handleValidation(BeanValidationOutInterceptor.java:45)
    org.apache.cxf.validation.AbstractValidationInterceptor.handleMessage(AbstractVa

The class/method that's referenced above in the exception is only available in validation api 1.1. Hence, I want to exclude the modules 'javax.validation.api' and 'org.hibernate.validator' that's provided by JBoss, so that the jars that are bundled within the war file can be used instead. For that, I created a jboss-deployment-structure.xml file with the below contents and placed it in the app's WEB-INF folder:

<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="javax.validation.api" />
            <module name="org.hibernate.validator" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

Now, I get this error instead:

java.lang.NoSuchMethodError: javax.validation.spi.ConfigurationState.getParameterNameProvider()Ljavax/validation/ParameterNameProvider;
    org.hibernate.validator.internal.engine.ValidatorFactoryImpl.<init>(ValidatorFactoryImpl.java:135)
    org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:45)
    org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:236)
    javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)

What am I doing wrong? How can I get bean validation 1.1 to work in JBoss 6.4.0?

1
Looks like the new Hibernate Validator version is picked up, but not the new Bean Validation API. Maybe you could verify in the log which version of Validator gets bootstrapped. How do you use Bean Validation? Do you boostrap your own Validator?Hardy
@Hardy, my application is CXF based restful web service. So, I just define a for org.apache.cxf.validation.BeanValidationFeature and add it as a feature as described here. CXF 3.1.0 depends on bean validation 1.1.Anand Jayabalan
You can use 1.1 See my answer here - stackoverflow.com/a/35091986/1308685Jeremy

1 Answers

1
votes

Warning in JBoss EAP all jee api are provided by a single module : javaee.api So if you want to upgrade only one you need to exclude javaee.api and reinclude all others. So use following jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
        <exclusions>
            <module name="javaee.api" />
        </exclusions>
        <dependencies>
            <module name="javax.activation.api" export="true" />
            <module name="javax.annotation.api" export="true" />
            <module name="javax.ejb.api" export="true" />
            <module name="javax.el.api" export="true" />
            <module name="javax.enterprise.api" export="true" />
            <module name="javax.enterprise.deploy.api" export="true" />
            <module name="javax.inject.api" export="true" />
            <module name="javax.interceptor.api" export="true" />
            <module name="javax.jms.api" export="true" />
            <module name="javax.jws.api" export="true" />
            <module name="javax.mail.api" export="true" />
            <module name="javax.management.j2ee.api" export="true" />
            <module name="javax.persistence.api" export="true" />
            <module name="javax.resource.api" export="true" />
            <module name="javax.rmi.api" export="true" />
            <module name="javax.security.auth.message.api" export="true" />
            <module name="javax.security.jacc.api" export="true" />
            <module name="javax.servlet.api" export="true" />
            <module name="javax.servlet.jsp.api" export="true" />
            <module name="javax.transaction.api" export="true" />
            <!-- remove the validation 1.0 <module name="javax.validation.api" export="true" /> -->
            <module name="javax.ws.rs.api" export="false" services="export" />
            <module name="javax.xml.bind.api" export="true" />
            <module name="javax.xml.registry.api" export="true" />
            <module name="javax.xml.soap.api" export="true" />
            <module name="javax.xml.ws.api" export="true" />
            <!-- This one always goes last. -->
            <module name="javax.api" export="true" />
        </dependencies>
    </deployment>
</jboss-deployment-structure>