在Wildfly下加载杰克逊JSR310的依赖冲突

时间:2016-07-03 19:10:30

标签: maven jackson wildfly wildfly-10

当我使用Wildfly下的Jackson JSR310模块解析LocalDate字段时,它失败并出现以下异常:

 java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonParser.hasToken(Lcom/fasterxml/jackson/core/JsonToken;)Z

我使用wildfly-javaee7-with-tools进行依赖关系管理。我pom.xml的有趣部分:

<properties>
    <version.wildfly>10.0.0.Final</version.wildfly>
    <version.jackson>2.6.3</version.jackson>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.wildfly.bom</groupId>
            <artifactId>wildfly-javaee7-with-tools</artifactId>
            <version>${version.wildfly}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson2-provider</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-hibernate5</artifactId>
        <version>${version.jackson}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jdk8</artifactId>
        <version>${version.jackson}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
        <version>${version.jackson}</version>
    </dependency>
</dependencies>

我的提供者:

@Provider
public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {

    private final ObjectMapper objectMapper;

    public ObjectMapperProvider() {
        this.objectMapper = new ObjectMapper();
        objectMapper.registerModule(new Jdk8Module());
        objectMapper.registerModule(new JavaTimeModule());
        objectMapper.registerModule(new Hibernate5Module());
    }

    @Override
    public ObjectMapper getContext(Class<?> aClass) {
        return objectMapper;
    }

}

这显然看起来像是依赖冲突。然而,这是mvn dependency:tree的输出,杰克逊相关的所有内容似乎都在2.6.3上。

[INFO] +- javax:javaee-web-api:jar:7.0:provided
[INFO] +- org.jboss.resteasy:resteasy-jackson2-provider:jar:3.0.14.Final:provided
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.6.3:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.3:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.3:compile
[INFO] |  \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-prov ider:jar:2.6.3:provided
[INFO] |     +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.6.3:provided
[INFO] |     \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.6.3:provided
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-hibernate5:jar:2.6.3:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.6.3:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.6.3:compile

我也在Wildfly 10.0.0.Final服务器上运行,因此我不希望10.0.0.Final pom.xml与服务器上提供的实际依赖关系之间的版本不匹配。

1 个答案:

答案 0 :(得分:2)

检查此文件夹并检查版本。 wildfly-10.0.0.Final\modules\system\layers\base\com\fasterxml\jackson\core\jacks‌​on-core\main. 我非常确定你需要自己指定jackson-core 2.6.3依赖项,因为org.jboss.resteasy:resteasy-jackson2-provider:jar:3.0.14.Final是提供范围的,而wildfly 10中不存在2.6.3。