jar包冲突报错java.lang.NoClassDefFoundError

现象:

程序启动失败,报错信息如下

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grpc.client-com.xxx.core.grpc.GrpcClientProperties': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.xxx.core.grpc.GrpcClientProperties]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/xxx/infrastructure/grpc/GrpcConfig

根据报错信息可以初步判断是pom中引用的jar包存在冲突,如何定位到是哪个jar包冲突的,分享一下我的思路。

  1. 首先确定导致jar包冲突的类是com.xxx.core.grpc.GrpcClientProperties,那么应该是有两个jar包中存在相同路径相同名称的两个类。
  2. 在当前工程中,全局搜索GrpcClientProperties这个类,发现没有直接引用
  3. 在其他能正常启动的工程中全局搜索这个类GrpcClientProperties,定位到Maven坐标com.xxx.rpc:rpc-core:1.3.9.8-RELEASE
  4. 在当前工程中查看Maven引用树mvn dependency:tree,搜索rpc-core看是哪个jar包引进来的,定位到
    <dependency>
        <groupId>com.xxx.authorization</groupId>
        <artifactId>authorization-interface</artifactId>
        <version>1.1.1105-SNAPSHOT</version>
    </dependency>
  5. 将rpc-core排除
    <dependency>
       <groupId>com.xxx.authorization</groupId>
       <artifactId>authorization-interface</artifactId>
       <version>1.1.1105-SNAPSHOT</version>
       <exclusions>
           <exclusion>
              <groupId>com.xxx.rpc</groupId>
              <artifactId>rpc-core</artifactId>
           </exclusion>
       </exclusions>
    </dependency>

    重新启动,服务正常

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值