问题描述

错误信息

idea 导入项目报错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xmlModelPlugin': Failed to introspect bean class [springfox.documentation.schema.XmlModelPlugin] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlType
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1122)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:123)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:666)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:353)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:300)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1082)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1071)
	at com.cqts.manage.Application.main(Application.java:24)
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlType
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3167)
	at java.base/java.lang.Class.getDeclaredMethods(Class.java:2310)
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:612)
	at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:523)
	at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:509)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:245)
	... 18 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlType
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 25 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:49903', transport: 'socket'

Process finished with exit code 1

注意: 其他人运行同样的代码没问题。

问题解决

找了很久原因,百度上一些说是缺少依赖。但是其他人也能运行,说明不一定是缺少依赖。当然引入了百度出来的一些依赖同样报错。最后发现是jdk版本问题。

导入的时候jdk运行环境默认到了jdk11,然而这个项目开发的时候用的jdk8而且spring boot版本也有些老了。1.5.x的。

最终解决办法就是,jdk11(jre) 切换到 jdk8(jre) 解决问题
运行环境jdk/jre切换版本

 

评论区域