【已解决】升级至JDK11,报java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException

问题描述

Springboot项目从JDK8升级至JDK11,编译通过,启动运行时出现下面的错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectMapperConfigurer' defined in class path resource [springfox/documentation/spring/web/SpringfoxWebMvcConfiguration.class]:
BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': BeanPostProcessor before instantiation of bean failed; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.config.internalCacheAdvisor' defined in class path resource [org/springframework/cache/annotation/ProxyCachingConfiguration.class]: Bean instantiation via factory method failed; 
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor]: Factory method 'cacheAdvisor' threw exception; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cacheAutoConfigurationValidator': Unsatisfied dependency expressed through field 'cacheProperties'; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.cache-org.springframework.boot.autoconfigure.cache.CacheProperties': Initialization of bean failed; 
nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException

意思是初始化objectMapperConfigurer时,出现了NoClassDefFoundError,因为找不到 javax/xml/bind/ValidationException 这个类。

问题分析

  • 项目中切回JDK8,查找javax/xml/bind/ValidationException 这个类,可以发现,它在 rt.jar 这个包里;

  • 项目中切回JDK11,查找javax/xml/bind/ValidationException 这个类,已经从JDK里找不到了,说明时缺少相关Jar包。
    在这里插入图片描述

补充:
从java 9中引入了模块的概念,默认情况下,Java SE中将不再包含java EE 的Jar包,因此不再包含在Java SE 9默认的类路径,而在 java 6/7/8 时关于这个API都是捆绑在一起的。
在Java11中,它们完全从JDK中删除。
上图中的jaxb-api 就是Java EE的jar包,所以不存在。

问题解决

手动引入相关Jar包:

<!--maven中引入-->
<dependency>
	<groupId>javax.xml.bind</groupId>
	<artifactId>jaxb-api</artifactId>
	<version>2.3.1</version>
</dependency>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值