如何在JBoss EAP 6.4.0中使用bean验证1.1? [英] How to use bean validation 1.1 in JBoss EAP 6.4.0?

查看:169
本文介绍了如何在JBoss EAP 6.4.0中使用bean验证1.1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的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),因此存在冲突,并且没有任何服务调用工作。以下是我得到的错误:

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

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

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>

现在,我收到此错误:

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?

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

推荐答案

JBoss EAP中的警告所有jee api都是由一个模块提供的:javaee.api
所以如果你想要的话只升级一个你需要排除javaee.api并重新包括所有其他人。
所以请使用以下jboss-deployment-structure.xml

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>

这篇关于如何在JBoss EAP 6.4.0中使用bean验证1.1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆