class com.fasterxml.jackson.dataformat.xml.XmlMapper 正在从多个位置加载

class com.fasterxml.jackson.dataformat.xml.XmlMapper is loading from from multiple locations

我很困惑如何用 Java 11 解决这个 com.fasterxml.jackson.dataformat.xml.XmlMapper 错误。我只想从 jackson 依赖项中使用 XmlMapper,这就是为什么从 springboot starter web 中排除的原因,仍然不知道如何解决它依赖。提供尽可能多的细节 -

build.gradle

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
        
    }
    jaxb
    fatJar
}

repositories {
    mavenCentral()
}

dependencies {
    implementation ('org.springframework.boot:spring-boot-starter-web') {
        exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core'
        exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
        exclude group: 'com.fasterxml.jackson.core', module: 'jackson-annotations'
    }
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    compileOnly 'org.projectlombok:lombok:1.18.4'
    annotationProcessor 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.12.2'
    
    compile("com.newrelic.logging:logback:2.0")
    implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.4'
    jaxb (
        'com.sun.xml.bind:jaxb-xjc:2.3.1',
        'com.sun.xml.bind:jaxb-impl:2.3.1',
        'org.glassfish.jaxb:jaxb-runtime:2.3.3'
    )
}

依赖层次结构

+--- com.newrelic.logging:logback:2.0
+--- org.springframework.boot:spring-boot-starter-web -> 2.4.5
|    +--- org.springframework.boot:spring-boot-starter:2.4.5
|    |    +--- org.springframework.boot:spring-boot:2.4.5
|    |    |    +--- org.springframework:spring-core:5.3.6
|    |    |    |    \--- org.springframework:spring-jcl:5.3.6
|    |    |    \--- org.springframework:spring-context:5.3.6
|    |    |         +--- org.springframework:spring-aop:5.3.6
|    |    |         |    +--- org.springframework:spring-beans:5.3.6
|    |    |         |    |    \--- org.springframework:spring-core:5.3.6 (*)
|    |    |         |    \--- org.springframework:spring-core:5.3.6 (*)
|    |    |         +--- org.springframework:spring-beans:5.3.6 (*)
|    |    |         +--- org.springframework:spring-core:5.3.6 (*)
|    |    |         \--- org.springframework:spring-expression:5.3.6
|    |    |              \--- org.springframework:spring-core:5.3.6 (*)
|    |    +--- org.springframework.boot:spring-boot-autoconfigure:2.4.5
|    |    |    \--- org.springframework.boot:spring-boot:2.4.5 (*)
|    |    +--- org.springframework.boot:spring-boot-starter-logging:2.4.5
|    |    |    +--- ch.qos.logback:logback-classic:1.2.3
|    |    |    |    +--- ch.qos.logback:logback-core:1.2.3
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|    |    |    +--- org.apache.logging.log4j:log4j-to-slf4j:2.13.3
|    |    |    |    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.13.3
|    |    |    \--- org.slf4j:jul-to-slf4j:1.7.30
|    |    |         \--- org.slf4j:slf4j-api:1.7.30
|    |    +--- jakarta.annotation:jakarta.annotation-api:1.3.5
|    |    +--- org.springframework:spring-core:5.3.6 (*)
|    |    \--- org.yaml:snakeyaml:1.27
|    +--- org.springframework.boot:spring-boot-starter-json:2.4.5
|    |    +--- org.springframework.boot:spring-boot-starter:2.4.5 (*)
|    |    +--- org.springframework:spring-web:5.3.6
|    |    |    +--- org.springframework:spring-beans:5.3.6 (*)
|    |    |    \--- org.springframework:spring-core:5.3.6 (*)
|    |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.4
|    |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.4
|    |    \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.4
|    +--- org.springframework.boot:spring-boot-starter-tomcat:2.4.5
|    |    +--- jakarta.annotation:jakarta.annotation-api:1.3.5
|    |    +--- org.apache.tomcat.embed:tomcat-embed-core:9.0.45
|    |    +--- org.glassfish:jakarta.el:3.0.3
|    |    \--- org.apache.tomcat.embed:tomcat-embed-websocket:9.0.45
|    |         \--- org.apache.tomcat.embed:tomcat-embed-core:9.0.45
|    +--- org.springframework:spring-web:5.3.6 (*)
|    \--- org.springframework:spring-webmvc:5.3.6
|         +--- org.springframework:spring-aop:5.3.6 (*)
|         +--- org.springframework:spring-beans:5.3.6 (*)
|         +--- org.springframework:spring-context:5.3.6 (*)
|         +--- org.springframework:spring-core:5.3.6 (*)
|         +--- org.springframework:spring-expression:5.3.6 (*)
|         \--- org.springframework:spring-web:5.3.6 (*)
+--- org.springframework.boot:spring-boot-starter-actuator -> 2.4.5
|    +--- org.springframework.boot:spring-boot-starter:2.4.5 (*)
|    +--- org.springframework.boot:spring-boot-actuator-autoconfigure:2.4.5
|    |    +--- org.springframework.boot:spring-boot-actuator:2.4.5
|    |    |    \--- org.springframework.boot:spring-boot:2.4.5 (*)
|    |    +--- org.springframework.boot:spring-boot:2.4.5 (*)
|    |    \--- org.springframework.boot:spring-boot-autoconfigure:2.4.5 (*)
|    \--- io.micrometer:micrometer-core:1.6.6
|         \--- org.hdrhistogram:HdrHistogram:2.1.12
+--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.2
|    +--- com.fasterxml.jackson.core:jackson-core:2.12.2 -> 2.11.4
|    +--- com.fasterxml.jackson.core:jackson-annotations:2.12.2 -> 2.11.4
|    +--- com.fasterxml.jackson.core:jackson-databind:2.12.2 -> 2.11.4
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.11.4
|    |    \--- com.fasterxml.jackson.core:jackson-core:2.11.4
|    +--- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.12.2 -> 2.11.4
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.11.4
|    |    +--- com.fasterxml.jackson.core:jackson-core:2.11.4
|    |    +--- com.fasterxml.jackson.core:jackson-databind:2.11.4 (*)
|    |    +--- jakarta.xml.bind:jakarta.xml.bind-api:2.3.2 -> 2.3.3
|    |    |    \--- jakarta.activation:jakarta.activation-api:1.2.2
|    |    \--- jakarta.activation:jakarta.activation-api:1.2.1 -> 1.2.2
|    +--- org.codehaus.woodstox:stax2-api:4.2.1
|    +--- com.fasterxml.woodstox:woodstox-core:6.2.4
|    |    \--- org.codehaus.woodstox:stax2-api:4.2.1
|    \--- com.fasterxml.jackson:jackson-bom:2.12.2
|         +--- com.fasterxml.jackson.core:jackson-annotations:2.12.2 -> 2.11.4 (c)
|         +--- com.fasterxml.jackson.core:jackson-core:2.12.2 -> 2.11.4 (c)
|         +--- com.fasterxml.jackson.core:jackson-databind:2.12.2 -> 2.11.4 (c)
|         +--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.2 (c)
|         +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.2 -> 2.11.4 (c)
|         +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.2 -> 2.11.4 (c)
|         +--- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.12.2 -> 2.11.4 (c)
|         \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.12.2 -> 2.11.4 (c)
+--- javax.xml.bind:jaxb-api:2.2.4
|    +--- javax.xml.stream:stax-api:1.0-2
|    \--- javax.activation:activation:1.1
\--- org.springframework.boot:spring-boot-starter-test -> 2.4.5
     +--- org.springframework.boot:spring-boot-starter:2.4.5 (*)
     +--- org.springframework.boot:spring-boot-test:2.4.5
     |    \--- org.springframework.boot:spring-boot:2.4.5 (*)
     +--- org.springframework.boot:spring-boot-test-autoconfigure:2.4.5
     |    +--- org.springframework.boot:spring-boot:2.4.5 (*)
     |    +--- org.springframework.boot:spring-boot-test:2.4.5 (*)
     |    \--- org.springframework.boot:spring-boot-autoconfigure:2.4.5 (*)
     +--- com.jayway.jsonpath:json-path:2.4.0
     |    +--- net.minidev:json-smart:2.3
     |    |    \--- net.minidev:accessors-smart:1.2
     |    |         \--- org.ow2.asm:asm:5.0.4
     |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
     +--- jakarta.xml.bind:jakarta.xml.bind-api:2.3.3 (*)
     +--- org.assertj:assertj-core:3.18.1
     +--- org.hamcrest:hamcrest:2.2
     +--- org.junit.jupiter:junit-jupiter:5.7.1
     |    +--- org.junit:junit-bom:5.7.1
     |    |    +--- org.junit.jupiter:junit-jupiter:5.7.1 (c)
     |    |    +--- org.junit.jupiter:junit-jupiter-api:5.7.1 (c)
     |    |    +--- org.junit.jupiter:junit-jupiter-params:5.7.1 (c)
     |    |    \--- org.junit.platform:junit-platform-commons:1.7.1 (c)
     |    +--- org.junit.jupiter:junit-jupiter-api:5.7.1
     |    |    +--- org.junit:junit-bom:5.7.1 (*)
     |    |    +--- org.apiguardian:apiguardian-api:1.1.0
     |    |    +--- org.opentest4j:opentest4j:1.2.0
     |    |    \--- org.junit.platform:junit-platform-commons:1.7.1
     |    |         +--- org.junit:junit-bom:5.7.1 (*)
     |    |         \--- org.apiguardian:apiguardian-api:1.1.0
     |    \--- org.junit.jupiter:junit-jupiter-params:5.7.1
     |         +--- org.junit:junit-bom:5.7.1 (*)
     |         +--- org.apiguardian:apiguardian-api:1.1.0
     |         \--- org.junit.jupiter:junit-jupiter-api:5.7.1 (*)
     +--- org.mockito:mockito-core:3.6.28
     |    +--- net.bytebuddy:byte-buddy:1.10.18 -> 1.10.22
     |    +--- net.bytebuddy:byte-buddy-agent:1.10.18 -> 1.10.22
     |    \--- org.objenesis:objenesis:3.1
     +--- org.mockito:mockito-junit-jupiter:3.6.28
     |    \--- org.mockito:mockito-core:3.6.28 (*)
     +--- org.skyscreamer:jsonassert:1.5.0
     |    \--- com.vaadin.external.google:android-json:0.0.20131108.vaadin1
     +--- org.springframework:spring-core:5.3.6 (*)
     +--- org.springframework:spring-test:5.3.6
     |    \--- org.springframework:spring-core:5.3.6 (*)
     \--- org.xmlunit:xmlunit-core:2.7.0

testCompileOnly - Compile only dependencies for source set 'test'. (n)
No dependencies

testImplementation - Implementation only dependencies for source set 'test'. (n)
\--- org.springframework.boot:spring-boot-starter-test (n)

testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- com.newrelic.logging:logback:2.0
|    +--- com.fasterxml.jackson.core:jackson-core:2.11.1 -> 2.11.4
|    +--- ch.qos.logback:logback-core:1.2.0 -> 1.2.3
|    +--- ch.qos.logback:logback-classic:1.2.0 -> 1.2.3
|    |    +--- ch.qos.logback:logback-core:1.2.3
|    |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|    \--- com.newrelic.agent.java:newrelic-api:5.6.0
+--- org.springframework.boot:spring-boot-starter-web -> 2.4.5
|    +--- org.springframework.boot:spring-boot-starter:2.4.5
|    |    +--- org.springframework.boot:spring-boot:2.4.5
|    |    |    +--- org.springframework:spring-core:5.3.6
|    |    |    |    \--- org.springframework:spring-jcl:5.3.6
|    |    |    \--- org.springframework:spring-context:5.3.6
|    |    |         +--- org.springframework:spring-aop:5.3.6
|    |    |         |    +--- org.springframework:spring-beans:5.3.6
|    |    |         |    |    \--- org.springframework:spring-core:5.3.6 (*)
|    |    |         |    \--- org.springframework:spring-core:5.3.6 (*)
|    |    |         +--- org.springframework:spring-beans:5.3.6 (*)
|    |    |         +--- org.springframework:spring-core:5.3.6 (*)
|    |    |         \--- org.springframework:spring-expression:5.3.6
|    |    |              \--- org.springframework:spring-core:5.3.6 (*)
|    |    +--- org.springframework.boot:spring-boot-autoconfigure:2.4.5
|    |    |    \--- org.springframework.boot:spring-boot:2.4.5 (*)
|    |    +--- org.springframework.boot:spring-boot-starter-logging:2.4.5
|    |    |    +--- ch.qos.logback:logback-classic:1.2.3 (*)
|    |    |    +--- org.apache.logging.log4j:log4j-to-slf4j:2.13.3
|    |    |    |    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.13.3
|    |    |    \--- org.slf4j:jul-to-slf4j:1.7.30
|    |    |         \--- org.slf4j:slf4j-api:1.7.30
|    |    +--- jakarta.annotation:jakarta.annotation-api:1.3.5
|    |    +--- org.springframework:spring-core:5.3.6 (*)
|    |    \--- org.yaml:snakeyaml:1.27
|    +--- org.springframework.boot:spring-boot-starter-json:2.4.5
|    |    +--- org.springframework.boot:spring-boot-starter:2.4.5 (*)
|    |    +--- org.springframework:spring-web:5.3.6
|    |    |    +--- org.springframework:spring-beans:5.3.6 (*)
|    |    |    \--- org.springframework:spring-core:5.3.6 (*)
|    |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.4
|    |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.4
|    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.11.4
|    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.11.4
|    |    |    \--- com.fasterxml.jackson.core:jackson-databind:2.11.4
|    |    |         +--- com.fasterxml.jackson.core:jackson-annotations:2.11.4
|    |    |         \--- com.fasterxml.jackson.core:jackson-core:2.11.4
|    |    \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.4
|    +--- org.springframework.boot:spring-boot-starter-tomcat:2.4.5
|    |    +--- jakarta.annotation:jakarta.annotation-api:1.3.5
|    |    +--- org.apache.tomcat.embed:tomcat-embed-core:9.0.45
|    |    +--- org.glassfish:jakarta.el:3.0.3
|    |    \--- org.apache.tomcat.embed:tomcat-embed-websocket:9.0.45
|    |         \--- org.apache.tomcat.embed:tomcat-embed-core:9.0.45
|    +--- org.springframework:spring-web:5.3.6 (*)
|    \--- org.springframework:spring-webmvc:5.3.6
|         +--- org.springframework:spring-aop:5.3.6 (*)
|         +--- org.springframework:spring-beans:5.3.6 (*)
|         +--- org.springframework:spring-context:5.3.6 (*)
|         +--- org.springframework:spring-core:5.3.6 (*)
|         +--- org.springframework:spring-expression:5.3.6 (*)
|         \--- org.springframework:spring-web:5.3.6 (*)
+--- org.springframework.boot:spring-boot-starter-actuator -> 2.4.5
|    +--- org.springframework.boot:spring-boot-starter:2.4.5 (*)
|    +--- org.springframework.boot:spring-boot-actuator-autoconfigure:2.4.5
|    |    +--- com.fasterxml.jackson.core:jackson-databind:2.11.4 (*)
|    |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.4 (*)
|    |    +--- org.springframework.boot:spring-boot-actuator:2.4.5
|    |    |    \--- org.springframework.boot:spring-boot:2.4.5 (*)
|    |    +--- org.springframework.boot:spring-boot:2.4.5 (*)
|    |    \--- org.springframework.boot:spring-boot-autoconfigure:2.4.5 (*)
|    \--- io.micrometer:micrometer-core:1.6.6
|         +--- org.hdrhistogram:HdrHistogram:2.1.12
|         \--- org.latencyutils:LatencyUtils:2.0.3
+--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.2
|    +--- com.fasterxml.jackson.core:jackson-core:2.12.2 -> 2.11.4
|    +--- com.fasterxml.jackson.core:jackson-annotations:2.12.2 -> 2.11.4
|    +--- com.fasterxml.jackson.core:jackson-databind:2.12.2 -> 2.11.4 (*)
|    +--- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.12.2 -> 2.11.4
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.11.4
|    |    +--- com.fasterxml.jackson.core:jackson-core:2.11.4
|    |    +--- com.fasterxml.jackson.core:jackson-databind:2.11.4 (*)
|    |    +--- jakarta.xml.bind:jakarta.xml.bind-api:2.3.2 -> 2.3.3
|    |    |    \--- jakarta.activation:jakarta.activation-api:1.2.2
|    |    \--- jakarta.activation:jakarta.activation-api:1.2.1 -> 1.2.2
|    +--- org.codehaus.woodstox:stax2-api:4.2.1
|    +--- com.fasterxml.woodstox:woodstox-core:6.2.4
|    |    \--- org.codehaus.woodstox:stax2-api:4.2.1
|    \--- com.fasterxml.jackson:jackson-bom:2.12.2
|         +--- com.fasterxml.jackson.core:jackson-annotations:2.12.2 -> 2.11.4 (c)
|         +--- com.fasterxml.jackson.core:jackson-core:2.12.2 -> 2.11.4 (c)
|         +--- com.fasterxml.jackson.core:jackson-databind:2.12.2 -> 2.11.4 (c)
|         +--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.2 (c)
|         +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.2 -> 2.11.4 (c)
|         +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.2 -> 2.11.4 (c)
|         +--- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.12.2 -> 2.11.4 (c)
|         \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.12.2 -> 2.11.4 (c)
+--- javax.xml.bind:jaxb-api:2.2.4
|    +--- javax.xml.stream:stax-api:1.0-2
|    \--- javax.activation:activation:1.1
\--- org.springframework.boot:spring-boot-starter-test -> 2.4.5
     +--- org.springframework.boot:spring-boot-starter:2.4.5 (*)
     +--- org.springframework.boot:spring-boot-test:2.4.5
     |    \--- org.springframework.boot:spring-boot:2.4.5 (*)
     +--- org.springframework.boot:spring-boot-test-autoconfigure:2.4.5
     |    +--- org.springframework.boot:spring-boot:2.4.5 (*)
     |    +--- org.springframework.boot:spring-boot-test:2.4.5 (*)
     |    \--- org.springframework.boot:spring-boot-autoconfigure:2.4.5 (*)
     +--- com.jayway.jsonpath:json-path:2.4.0
     |    +--- net.minidev:json-smart:2.3
     |    |    \--- net.minidev:accessors-smart:1.2
     |    |         \--- org.ow2.asm:asm:5.0.4
     |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
     +--- jakarta.xml.bind:jakarta.xml.bind-api:2.3.3 (*)
     +--- org.assertj:assertj-core:3.18.1
     +--- org.hamcrest:hamcrest:2.2
     +--- org.junit.jupiter:junit-jupiter:5.7.1
     |    +--- org.junit:junit-bom:5.7.1
     |    |    +--- org.junit.jupiter:junit-jupiter:5.7.1 (c)
     |    |    +--- org.junit.jupiter:junit-jupiter-api:5.7.1 (c)
     |    |    +--- org.junit.jupiter:junit-jupiter-engine:5.7.1 (c)
     |    |    +--- org.junit.jupiter:junit-jupiter-params:5.7.1 (c)
     |    |    +--- org.junit.platform:junit-platform-commons:1.7.1 (c)
     |    |    \--- org.junit.platform:junit-platform-engine:1.7.1 (c)
     |    +--- org.junit.jupiter:junit-jupiter-api:5.7.1
     |    |    +--- org.junit:junit-bom:5.7.1 (*)
     |    |    +--- org.apiguardian:apiguardian-api:1.1.0
     |    |    +--- org.opentest4j:opentest4j:1.2.0
     |    |    \--- org.junit.platform:junit-platform-commons:1.7.1
     |    |         +--- org.junit:junit-bom:5.7.1 (*)
     |    |         \--- org.apiguardian:apiguardian-api:1.1.0
     |    +--- org.junit.jupiter:junit-jupiter-params:5.7.1
     |    |    +--- org.junit:junit-bom:5.7.1 (*)
     |    |    +--- org.apiguardian:apiguardian-api:1.1.0
     |    |    \--- org.junit.jupiter:junit-jupiter-api:5.7.1 (*)
     |    \--- org.junit.jupiter:junit-jupiter-engine:5.7.1
     |         +--- org.junit:junit-bom:5.7.1 (*)
     |         +--- org.apiguardian:apiguardian-api:1.1.0
     |         +--- org.junit.platform:junit-platform-engine:1.7.1
     |         |    +--- org.junit:junit-bom:5.7.1 (*)
     |         |    +--- org.apiguardian:apiguardian-api:1.1.0
     |         |    +--- org.opentest4j:opentest4j:1.2.0
     |         |    \--- org.junit.platform:junit-platform-commons:1.7.1 (*)
     |         \--- org.junit.jupiter:junit-jupiter-api:5.7.1 (*)
     +--- org.mockito:mockito-core:3.6.28
     |    +--- net.bytebuddy:byte-buddy:1.10.18 -> 1.10.22
     |    +--- net.bytebuddy:byte-buddy-agent:1.10.18 -> 1.10.22
     |    \--- org.objenesis:objenesis:3.1
     +--- org.mockito:mockito-junit-jupiter:3.6.28
     |    +--- org.mockito:mockito-core:3.6.28 (*)
     |    \--- org.junit.jupiter:junit-jupiter-api:5.4.2 -> 5.7.1 (*)
     +--- org.skyscreamer:jsonassert:1.5.0
     |    \--- com.vaadin.external.google:android-json:0.0.20131108.vaadin1
     +--- org.springframework:spring-core:5.3.6 (*)
     +--- org.springframework:spring-test:5.3.6
     |    \--- org.springframework:spring-core:5.3.6 (*)
     \--- org.xmlunit:xmlunit-core:2.7.0

启动应用程序 运行 时出错 -

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:175)

The following method did not exist:

    'com.fasterxml.jackson.databind.cfg.MutableCoercionConfig com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()'

The method's class, com.fasterxml.jackson.dataformat.xml.XmlMapper, is available from the following locations:

    jar:file:/C:/Users/user1/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.dataformat/jackson-dataformat-xml/2.12.2/dac1d21b5fe602d492273d35eb28918a91fc5412/jackson-dataformat-xml-2.12.2.jar!/com/fasterxml/jackson/dataformat/xml/XmlMapper.class

The class hierarchy was loaded from the following locations:

    com.fasterxml.jackson.dataformat.xml.XmlMapper: file:/C:/Users/user1/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.dataformat/jackson-dataformat-xml/2.12.2/dac1d21b5fe602d492273d35eb28918a91fc5412/jackson-dataformat-xml-2.12.2.jar
    com.fasterxml.jackson.databind.ObjectMapper: file:/C:/Users/user1/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.11.4/5d9f3d441f99d721b957e3497f0a6465c764fad4/jackson-databind-2.11.4.jar
    com.fasterxml.jackson.core.ObjectCodec: file:/C:/Users/user1/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.11.4/593f7b18bab07a76767f181e2a2336135ce82cc4/jackson-core-2.11.4.jar
    com.fasterxml.jackson.core.TreeCodec: file:/C:/Users/user1/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.11.4/593f7b18bab07a76767f181e2a2336135ce82cc4/jackson-core-2.11.4.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of com.fasterxml.jackson.dataformat.xml.XmlMapper

您是否明确需要 jackson-dataformat-xml 版本 2.12.2?

问题

jackson-dataformat-xml:2.12.2 与 jackson 依赖项 2.11.4 不兼容。 Spring 引导覆盖未在依赖项块或 dependencyManagement 中以其他方式指定的 Jackson 依赖项。

解决方案

如果您不需要 2.12.2,那么只需定义 jackson-dataformat-xml 如下:

  implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml'

然后解析的版本将是

com.fasterxml.jackson.dataformat:jackson-dataformat-xml -> 2.11.4

它将与所有其他 Jackson 组件兼容,您将不会再遇到此异常。始终尝试检查 Jackson 的依赖项并确保所有项都对齐。

例如,如果您 运行 'gradlew dependencies',您会得到以下结果,这是不好的:

+--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.2
|    +--- com.fasterxml.jackson.core:jackson-core:2.12.2 -> 2.11.4

Jackson 的版本没有正确对齐。通过管理 Gradle 依赖项,您必须确保对齐它们,这意味着升级或降级它们。

如果您确实需要明确的 2.12.2,那么您还应该升级 Spring 包含较新版本的引导版本。

您可以通过以下方式指定 Spring 启动版本:

dependencyManagement {
  imports {
    mavenBom 'org.springframework.boot:spring-boot-dependencies:2.5.0'
  }
}

当你只需要 XMLMapper 时,为什么要调用整个数据格式库?

我使用 Spring 找到了这个解决方法,因为我只需要 XMLMapper:

在声明中获取对消息转换器的引用:

private final MappingJackson2XmlHttpMessageConverter msgConverter;

以后只需从它的父对象中引用它:ObjectMapper

    ObjectMapper xmlMapper = xmlConverter.getObjectMapper();

这样你就不会陷入所描述的依赖问题。

所以,你只需要导入com.fasterxml.jackson.databind.ObjectMapper