ClassNotFoundException:XMLGregorianCalendar,Maven依赖关系已成功下载,但无法识别,

时间:2020-06-22 12:47:52

标签: java spring-boot maven java-11

我正在使用Java 11,Maven 3.6版和Spring Boot。我在运行单元时遇到问题 由于以下错误而进行测试:

    at java.base/java.lang.Class.getDeclaredFields0(Native Method) ~[na:na]
    at java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3061) ~[na:na]
    at java.base/java.lang.Class.getDeclaredFields(Class.java:2248) ~[na:na]
    at com.sun.xml.bind.v2.model.nav.ReflectionNavigator$3.run(ReflectionNavigator.java:288) ~[jaxb-core-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.nav.ReflectionNavigator$3.run(ReflectionNavigator.java:285) ~[jaxb-core-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
    at com.sun.xml.bind.v2.model.nav.ReflectionNavigator.getDeclaredFields(ReflectionNavigator.java:285) ~[jaxb-core-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.nav.ReflectionNavigator.getDeclaredFields(ReflectionNavigator.java:64) ~[jaxb-core-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.findFieldProperties(ClassInfoImpl.java:380) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.getProperties(ClassInfoImpl.java:311) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.impl.RuntimeClassInfoImpl.getProperties(RuntimeClassInfoImpl.java:186) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:261) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:103) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:84) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:227) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:98) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:84) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:375) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:390) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:465) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:303) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:139) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1156) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:165) ~[jaxb-runtime-2.3.0-b170127.1453.jar:2.3.0-b170127.1453]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:297) ~[jaxb-api-2.3.1.jar:2.3.0]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:286) ~[jaxb-api-2.3.1.jar:2.3.0]
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:409) ~[jaxb-api-2.3.1.jar:2.3.0]
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721) ~[jaxb-api-2.3.1.jar:2.3.0]
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662) ~[jaxb-api-2.3.1.jar:2.3.0]
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.createJaxbContextFromPackages(Jaxb2Marshaller.java:569) ~[spring-oxm-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.getJaxbContext(Jaxb2Marshaller.java:502) ~[spring-oxm-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.afterPropertiesSet(Jaxb2Marshaller.java:476) ~[spring-oxm-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    ... 40 common frames omitted
Caused by: java.lang.ClassNotFoundException: XMLGregorianCalendar

我知道在Java 11中java.xml.bind已删除,因此我在pom.xml文件中添加了依赖项

        <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0-b170127.1453</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.activation/activation -->
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.0-b170127.1453</version>
            <scope>runtime</scope>
        </dependency>

我检查了从maven依赖关系中下载的jar,并且存在javax.xml.datatype。如下所示: enter image description here

为什么会这样? XMLGregorianCalendar类怎么可能即使下载了id也无法识别?我该怎么做才能解决此问题?

我尝试运行:

  • mvn clean compile

  • mvn clean install

  • 我从Eclipse执行了Maven项目更新

以上操作均无效。

下面是运行命令mvn dependency:tree

的结果
[INFO] +- org.springframework.boot:spring-boot-starter-web-services:jar:2.1.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-web:jar:2.1.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-json:jar:2.1.0.RELEASE:compile
[INFO] |  |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.7:compile
[INFO] |  |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.7:compile
[INFO] |  |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.7:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.1.0.RELEASE:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.12:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.12:compile
[INFO] |  |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.12:compile
[INFO] |  |  +- org.springframework:spring-web:jar:5.1.2.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-webmvc:jar:5.1.2.RELEASE:compile
[INFO] |  |     \- org.springframework:spring-expression:jar:5.1.2.RELEASE:compile
[INFO] |  +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.5.0:compile
[INFO] |  |  +- javax.xml.soap:javax.xml.soap-api:jar:1.4.0:compile
[INFO] |  |  \- org.jvnet.mimepull:mimepull:jar:1.9.10:compile
[INFO] |  +- javax.xml.ws:jaxws-api:jar:2.3.1:compile
[INFO] |  |  \- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  +- org.springframework:spring-oxm:jar:5.1.2.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:5.1.2.RELEASE:compile
[INFO] |  \- org.springframework.ws:spring-ws-core:jar:3.0.4.RELEASE:compile
[INFO] |     +- org.springframework.ws:spring-xml:jar:3.0.4.RELEASE:compile
[INFO] |     \- org.springframework:spring-aop:jar:5.1.2.RELEASE:compile
[INFO] +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] |  \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] +- javax.activation:activation:jar:1.1:compile
[INFO] +- org.glassfish.jaxb:jaxb-runtime:jar:2.3.0-b170127.1453:compile
[INFO] |  +- org.glassfish.jaxb:jaxb-core:jar:2.3.0-b170127.1453:compile
[INFO] |  |  +- org.glassfish.jaxb:txw2:jar:2.3.0-b170127.1453:compile
[INFO] |  |  \- com.sun.istack:istack-commons-runtime:jar:3.0.4:compile
[INFO] |  +- org.jvnet.staxex:stax-ex:jar:1.7.8:compile
[INFO] |  \- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.13:compile
[INFO] |     |  +- org.elasticsearch.client:transport:jar:6.4.2:compile
[INFO] |     |  |  +- org.elasticsearch:elasticsearch:jar:6.4.2:compile
[INFO] |     |  |  |  +- org.elasticsearch:elasticsearch-core:jar:6.4.2:compile
[INFO] |     |  |  |  +- org.elasticsearch:elasticsearch-secure-sm:jar:6.4.2:compile
[INFO] |     |  |  |  +- org.elasticsearch:elasticsearch-x-content:jar:6.4.2:compile
[INFO] |     |  |  |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.9.7:compile
[INFO] |     |  |  |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.9.7:compile
[INFO] |     |  |  |  |  \- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.9.7:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-core:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-analyzers-common:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-backward-codecs:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-grouping:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-highlighter:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-join:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-memory:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-misc:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-queries:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-queryparser:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-sandbox:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-spatial:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-spatial-extras:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-spatial3d:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.apache.lucene:lucene-suggest:jar:7.4.0:compile
[INFO] |     |  |  |  +- org.elasticsearch:elasticsearch-cli:jar:6.4.2:compile
[INFO] |     |  |  |  |  \- net.sf.jopt-simple:jopt-simple:jar:5.0.2:compile
[INFO] |     |  |  |  +- com.carrotsearch:hppc:jar:0.7.1:compile
[INFO] |     |  |  |  +- com.tdunning:t-digest:jar:3.2:compile
[INFO] |     |  |  |  +- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
[INFO] |     |  |  |  \- org.elasticsearch:jna:jar:4.5.1:compile
[INFO] |     |  |  +- org.elasticsearch.plugin:reindex-client:jar:6.4.2:compile
[INFO] |     |  |  |  \- org.elasticsearch.client:elasticsearch-rest-client:jar:6.4.2:compile
[INFO] |     |  |  +- org.elasticsearch.plugin:lang-mustache-client:jar:6.4.2:compile
[INFO] |     |  |  |  \- com.github.spullara.mustache.java:compiler:jar:0.9.3:compile
[INFO] |     |  |  +- org.elasticsearch.plugin:percolator-client:jar:6.4.2:compile
[INFO] |     |  |  +- org.elasticsearch.plugin:parent-join-client:jar:6.4.2:compile
[INFO] |     |  |  \- org.elasticsearch.plugin:rank-eval-client:jar:6.4.2:compile
[INFO] |     |  \- org.elasticsearch.plugin:transport-netty4-client:jar:6.4.2:compile
[INFO] |     |     +- io.netty:netty-buffer:jar:4.1.29.Final:compile
[INFO] |     |     +- io.netty:netty-codec:jar:4.1.29.Final:compile
[INFO] |     |     +- io.netty:netty-codec-http:jar:4.1.29.Final:compile
[INFO] |     |     +- io.netty:netty-common:jar:4.1.29.Final:compile
[INFO] |     |     +- io.netty:netty-handler:jar:4.1.29.Final:compile
[INFO] |     |     +- io.netty:netty-resolver:jar:4.1.29.Final:compile
[INFO] |     |     \- io.netty:netty-transport:jar:4.1.29.Final:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.1.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:2.1.0.RELEASE:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-starter-logging:jar:2.1.0.RELEASE:compile
[INFO] |  |     +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |     |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |     \- org.apache.logging.log4j:log4j-to-slf4j:jar:2.11.1:compile
[INFO] |  |  |  +- org.elasticsearch.client:rest:jar:5.2.2:compile
[INFO] |  |  |  |  +- org.apache.httpcomponents:httpasyncclient:jar:4.1.4:compile
[INFO] |  |  |  |  \- org.apache.httpcomponents:httpcore-nio:jar:4.4.10:compile
[INFO] |  |  |  +- org.elasticsearch.client:sniffer:jar:5.2.2:compile
[INFO] |  |  |  +- org.json:json:jar:20160810:compile
[INFO] |  |  |  \- org.apache.logging.log4j:log4j-web:jar:2.11.1:compile
[INFO] |  |  +- org.apache.commons:commons-jcs-jcache:jar:2.1:compile
[INFO] |  |  |  \- org.apache.commons:commons-jcs-core:jar:2.1:compile
[INFO] |  |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  |  |  +- com.google.code.gson:gson:jar:2.8.5:compile
[INFO] |  |  |  \- org.mongodb:mongodb-driver:jar:3.8.2:compile
[INFO] |  |  |     \- org.mongodb:mongodb-driver-core:jar:3.8.2:compile
[INFO] |  |  \- org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] |  \- jaxen:jaxen:jar:1.1.6:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.1.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.1.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.0.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.3:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |        \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:3.11.1:test
[INFO] |  +- org.mockito:mockito-core:jar:2.23.0:test
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.9.3:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.9.3:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.6:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:5.1.2.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.1.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-test:jar:5.1.2.RELEASE:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.6.2:test
[INFO] +- org.springframework.boot:spring-boot-starter-log4j2:jar:2.1.0.RELEASE:test
[INFO] |  +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.11.1:test
[INFO] |  |  \- org.apache.logging.log4j:log4j-api:jar:2.11.1:compile
[INFO] |  +- org.apache.logging.log4j:log4j-core:jar:2.11.1:compile
[INFO] |  +- org.apache.logging.log4j:log4j-jul:jar:2.11.1:test
[INFO] |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] +- org.hibernate.validator:hibernate-validator:jar:6.0.13.Final:test
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:test
[INFO] |  \- com.fasterxml:classmate:jar:1.4.0:test
[INFO] +- com.github.javafaker:javafaker:jar:0.16:test
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.8.1:compile
[INFO] |  +- org.yaml:snakeyaml:jar:android:1.20:test
[INFO] |  \- com.github.mifmif:generex:jar:1.0.2:test
[INFO] |     \- dk.brics.automaton:automaton:jar:1.11-8:test
[INFO] \- com.devskiller:jfairy:jar:0.6.2:test
[INFO]    +- org.yaml:snakeyaml:jar:1.23:compile
[INFO]    +- org.apache.commons:commons-text:jar:1.2:compile
[INFO]    +- org.apache.commons:commons-math3:jar:3.6.1:test
[INFO]    +- com.google.guava:guava:jar:24.0-jre:compile
[INFO]    |  +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO]    |  +- org.checkerframework:checker-compat-qual:jar:2.0.0:compile
[INFO]    |  +- com.google.errorprone:error_prone_annotations:jar:2.1.3:compile
[INFO]    |  +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO]    |  \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile
[INFO]    +- com.google.inject:guice:jar:4.2.0:test
[INFO]    |  +- javax.inject:javax.inject:jar:1:compile
[INFO]    |  \- aopalliance:aopalliance:jar:1.0:test
[INFO]    +- com.google.inject.extensions:guice-assistedinject:jar:4.2.0:test
[INFO]    +- org.iban4j:iban4j:jar:3.2.1:test
[INFO]    \- org.codehaus.groovy:groovy-all:jar:2.4.14:test

1 个答案:

答案 0 :(得分:0)

“欢迎来到地狱”应该是这个问题的标题。

您已正确说明从Java 11中删除了javax.xml.bind模块,并且在Java 9和Java 10中也已弃用该模块。 您已使用以下命令正确替换了删除javax.xml.bind模块中缺少的依赖项:

     <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0-b170127.1453</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.activation/activation -->
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.0-b170127.1453</version>
            <scope>runtime</scope>
        </dependency>

我创建了一个新的maven项目并添加了以上依赖项。我能够成功运行项目 声明类型为javax.xml.datatype.XMLGregorianCalendar的变量。

我认为您不需要xml-apis,这是dom4j的传递依赖项。我认为如果您删除 xml-apis来自dom4j,此问题将得到解决。进行以下修改:

<dependency>
   <groupId>dom4j</groupId>
   <artifactId>dom4j</artifactId>
   <version>1.6.1</version>
   <exclusions>
      <exclusion>
         <groupId>xml-apis</groupId>
         <artifactId>xml-apis</artifactId>
      </exclusion>
   </exclusions>
</dependency>

如果dom4j是pom中某些其他依赖项的传递依赖项,那么您应该首先找到哪个依赖项具有dom4j作为传递依赖项。然后,您应该进行以下修改:

<dependency>
   <groupId>{the dependency group id that has dom4j as transitive dependency}</groupId>
   <artifactId>{the dependency artifact that has dom4j as transitive dependency}</artifactId>
   <version>1.6.1</version>
   <exclusions>
      <exclusion>
         <groupId>xml-apis</groupId>
         <artifactId>xml-apis</artifactId>
      </exclusion>
   </exclusions>
</dependency>

说明

我认为这个问题源于具有相同工件和不同组ID的依赖关系,而maven无法区分它们。 xml-apis构件可以来自xerces组织或来自xml-apis组织,如下所示:

<dependency>
    <groupId>org.apache.xerces</groupId>
    <artifactId>xml-apis</artifactId>
    <version>2.9.1</version>
    <scope>runtime</scope>
</dependency>

<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.10</version>
</dependency>

尽管它们具有相同的工件,但是maven不能将它们识别为相同的,因为它们具有不同的组ID。这不会引起冲突,并且两个依赖性都作为已解决的依赖性包括在内。 我的建议是,从xml-apis中排除dom4j并更新项目。

我希望这可以帮助您解决问题。