【发布时间】:2020-06-22 12:47:52
【问题描述】:
我正在使用 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。如下所示:
为什么会这样? 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
【问题讨论】:
-
从内存中,当加载类出现任何问题时会抛出 ClassNotFoundException(通常是静态初始化程序遇到异常) - 所以这可能与 NoClassDefFoundError 不同,后者是没有要加载的类定义的地方
-
是的,你是对的,问题是ClassNotFoundException,我根据异常编辑了问题的标题
-
当时我还是有点疑惑,所以我认为类定义可能被类加载器找到了,但加载失败。当我在我的笔记本电脑上时,我确实快速浏览了这个类,并没有看到那里的静态初始化程序,请注意我忘了检查是否有任何静态成员,也许是初始值会导致问题?我想我可能会在 ClassLoader 中放置一个(条件)断点,看看它尝试加载 XMLGregorianCalendar 时会发生什么
-
我在ClassLoader.loadClass上放了一个断点,但是没有进入,同样的错误失败
-
这听起来像是一个有点可怕的问题。再次查看您的堆栈跟踪,我猜声明的字段之一是 XMLGregorianCalendar 类型,然后它是遇到问题的本机方法,这就是您不会遇到断点的原因。不确定本机方法如何受到 ClassNotFoundException 的影响 - 在我的知识范围之外,不幸的是,这将是一个稍微痛苦的问题,除非您可以将一小段代码组合在一起来重现该问题。如果我有什么想法,我会告诉你的
标签: java spring-boot maven java-11