Wildfly and Jackson: LinkageError

2019-04-08 02:55发布

问题:

I'm trying to configure jboss wildfly 8 to use Jackson for JSON. So I added

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson-provider</artifactId>
    <version>3.0.6.Final</version>
    <type>jar</type>
</dependency>

to my ear project. But on deploying I get following error:

Caused by: java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider$Proxy$_$$WeldClientProxy.disable(Lorg/codehaus/jackson/map/Des erializationConfig$Feature;Z)Lorg/codehaus/jackson/jaxrs/JacksonJsonProvider;" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the current class, org/jboss/resteasy/plugins/providers/jackson/ResteasyJacksonPr ovider$Proxy$$$WeldClientProxy, and its superclass loader (instance of org/jboss/modules/ModuleClassLoader), have different Class objects for the type sy.plugins.providers.jackson.ResteasyJacksonProvider$Proxy$$$_WeldClientProx y.disable(Lorg/codehaus/jackson/map/DeserializationConfig$Feature;Z)Lorg/codehaus/jackson/jaxrs/JacksonJsonProvider; used in the signature

Is version 3.0.6 not compatible with Wildfly? how do I know which version works? I also tried with 2.3.7 and 1.1 but always the same error.

EDIT:

I have a ejb module with pojos. Here I have the dependency:

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.2.3</version>
        <scope>provided</scope>
        <type>jar</type>
    </dependency>

so that looks very much like jackson 2 to me.

and in my ear, I have following dependency:

<dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
        <version>3.0.6.Final</version>
        <type>jar</type>
        <scope>provided</scope>
</dependency>

do I need resteasy-jackson2-provider now? Do I need the jboss-deployment-structure.xml now?

回答1:

WildFly 8 already includes Jackson. Mark the dependency with <scope>provided</scope>. You then need to add a jboss-deployment-structure.xml to your deployment with the following per the documentation.

<jboss-deployment-structure>
    <deployment>
        <exclusions>
           <module name="org.jboss.resteasy.resteasy-jackson-provider"/>
        </exclusions>
        <dependencies>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure> 


回答2:

It worked for me when I imported <module name = "com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" />, because <module name = "org.jboss.resteasy.resteasy-jackson2-provider" services = "Import" /> does not export it

<jboss-deployment-structure>
      <sub-deployment name="erp-integrator.jar">
        <exclusions>
           <module name="org.jboss.resteasy.resteasy-jackson-provider"/>
        </exclusions>
        <dependencies>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import" />
            <module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" />
        </dependencies>
    </sub-deployment>
</jboss-deployment-structure>