现象:
程序启动失败,报错信息如下
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包冲突的,分享一下我的思路。
- 首先确定导致jar包冲突的类是com.xxx.core.grpc.GrpcClientProperties,那么应该是有两个jar包中存在相同路径相同名称的两个类。
- 在当前工程中,全局搜索GrpcClientProperties这个类,发现没有直接引用
- 在其他能正常启动的工程中全局搜索这个类GrpcClientProperties,定位到Maven坐标com.xxx.rpc:rpc-core:1.3.9.8-RELEASE
- 在当前工程中查看Maven引用树mvn dependency:tree,搜索rpc-core看是哪个jar包引进来的,定位到
<dependency> <groupId>com.xxx.authorization</groupId> <artifactId>authorization-interface</artifactId> <version>1.1.1105-SNAPSHOT</version> </dependency>
- 将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>
重新启动,服务正常