How to use bean validation 1.1 in JBoss EAP 6.4.0?

ぃ、小莉子 提交于 2019-12-24 05:23:14

问题


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:


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>


来源:https://stackoverflow.com/questions/30881589/how-to-use-bean-validation-1-1-in-jboss-eap-6-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!