如何在JBoss EAP 6.4.0中使用bean验证1.1?

时间:2015-06-17 03:00:41

标签: java java-ee jboss bean-validation

我有一个简单的restful Web服务,它使用Bean Validation 1.1(和Hibernate Validator 5.1.3作为实现),并且我将它部署在JBoss EAP 6.4.0上。由于JBoss 6.4捆绑了Bean Validation 1.0及其实现库(Hibernate Validator 4.3.2),因此存在冲突,并且没有任何服务调用。以下是我得到的错误:

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

异常中上面引用的类/方法仅在验证api 1.1中可用。因此,我想排除模块' javax.validation.api'和' org.hibernate.validator'这是由JBoss提供的,因此可以使用war文件中捆绑的jar。为此,我创建了一个带有以下内容的 jboss-deployment-structure.xml 文件,并将其放在应用程序的WEB-INF文件夹中:

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

现在,我收到了这个错误:

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)

我做错了什么?如何在JBoss 6.4.0中使用bean验证1.1?

1 个答案:

答案 0 :(得分:1)

JBoss EAP中的警告所有jee api都由一个模块提供:javaee.api 因此,如果您只想升级一个,则需要排除javaee.api并重新包含所有其他内容。 所以使用以下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>