JBoss - How can to exclude javax.validation in jboss-deployment-structure?

我怕爱的太早我们不能终老 提交于 2019-12-22 10:27:43

问题


I have .war using Jersey REST, and it works in tomCat. But I need to run my .war in JBoss 6.4.0 which causes an exception

java.lang.RuntimeException: java.lang.NoSuchMethodError:
javax.validation.spi.ConfigurationState.getParameterNameProvider()

because JBoss uses old version javax.validation, and I need to exclude javax.validation from deployment of JBoss.

I create jboss-deployment-structure.xml in WEB-INF of .war:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>

    <deployment>

        <exclude-subsystems>
            <subsystem name="resteasy" />
            <subsystem name="jpa"/>
            <subsystem name="org.hibernate" />
            <subsystem name="org.hibernate.validator" />
        </exclude-subsystems>

        <exclusions>
            <module name="javaee.api" />
            <module name="javax.ws.rs.api"/>
            <module name="org.jboss.resteasy.resteasy-jaxrs"/>
            <module name="javax.validation.api"/>
            <module name="org.hibernate"/>
            <module name="org.hibernate.validator"/>
        </exclusions>   

    </deployment>
</jboss-deployment-structure>

This helped me to exclude javax.ws.rs, but How can to exclude javax.validation? Help me, please


回答1:


Ok, so You need to exclude not only

<module name="javax.validation.api"/> 

itself, but also modules that are dependent on javax.validation.api module. The easiest way to see which modules are dependent on javax.validation.api and force it to be included, even though it was excluded, is to search your .xml files in JBOSS_DIRECTORY/modules for javax.validation.api, the modules that are dependent have something like that in module.xml:

<dependencies>>
    <module name="javax.validation.api"/>
...

And those modules need to be excluded as well. For me - I also needed to exclude:

        <module name="javax.faces.api"/>
        <module name="org.jboss.resteasy.resteasy-hibernatevalidator-provider"/>

And then, javax validation eclusion was working :)




回答2:


So, it is something! May be help to someone: Library javax.validation.api in JBoss - belongs to Implicit module, documentation about implicit module: implicit module dependencies

So implicit modules are Automatic Dependencies, and their can exclusion, about this: class lading and automatic dependencies - part about Automatic Dependencies: Automatic dependencies can be excluded through the use of jboss-deployment-structure.xml. But this is not work! :(, and JBoss has bug with similar library javax.persistence, and it bug open in tasks.

So - what can to do?

  1. Update JBoss to 7.0.0 version, but now just Alpha and Beta versions :(
  2. Replace old javax.validation.api .jar on new version .jar (in EAP-6.4.0/modules/system/layers/base/javax/faces/api/main)
  3. Add custom version, and it tangled: change default config in EAP-6.4.0/modules/system/layers/base/javax/faces/api/main module.xml file, in line <module name="javax.validation.api" export="true"/> remove option export="true", result: <module name="javax.validation.api"/> This changed to allow you add a new custom library javax.validation. And create custom folder with name 1.1 in EAP-6.4.0/modules/system/layers/base/javax/validation/api, put in 1.1 folder new javax.validation .jar and model.xml.

model.xml:

<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.1" name="javax.validation.api" slot="1.1">
    <resources>
        <resource-root path="validation-api-1.1.0.Final.jar"/>
    </resources>

  <dependencies>
    <module name="org.jboss.logging"/>
  </dependencies>
</module>

params: slot - name custom folder (1.1), path - path to .jar library

Last: add module to jboss-deployment-structure.xml in project:

<dependencies>
  <module name="javax.validation.api" slot="1.1" export="true"/>
</dependencies>


来源:https://stackoverflow.com/questions/34293402/jboss-how-can-to-exclude-javax-validation-in-jboss-deployment-structure

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