java jar包冲突解决办法

博客详细描述了一个应用程序在启动时遇到的错误,该错误源于尝试调用不存在的OkHttp方法。问题归因于类路径中存在两个不同版本的`okhttp3.internal.http.RetryAndFollowUpInterceptor`。解决方案是检查并排除重复的jar包引用,特别是从华为云ESDK OBS Java包中排除OkHttp依赖。通过在Maven的exclusions标签中排除相关依赖,成功解决了版本冲突问题。

现象启动时报错:


2021-07-16 10:46:50.712 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    okhttp3.RealCall.<init>(RealCall.java:51)

The following method did not exist:

    okhttp3.internal.http.RetryAndFollowUpInterceptor.<init>(Lokhttp3/OkHttpClient;Z)V

The method's class, okhttp3.internal.http.RetryAndFollowUpInterceptor, is available from the following locations:

    jar:file:/D:/java/rep/com/huaweicloud/esdk-obs-java/3.21.4.1/esdk-obs-java-3.21.4.1.jar!/okhttp3/internal/http/RetryAndFollowUpInterceptor.class
    jar:file:/D:/java/rep/com/squareup/okhttp3/okhttp/3.8.1/okhttp-3.8.1.jar!/okhttp3/internal/http/RetryAndFollowUpInterceptor.class

It was loaded from the following location:

    file:/D:/java/rep/com/huaweicloud/esdk-obs-java/3.21.4.1/esdk-obs-java-3.21.4.1.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of okhttp3.internal.http.RetryAndFollowUpInterceptor

导致这个问题是项目引入了华为云的包esdk-obs-java

		</dependency>
		    <dependency>
		   <groupId>com.huaweicloud</groupId>
		   <artifactId>esdk-obs-java</artifactId>
		   <version>[3.21.4,)</version>
		</dependency>

报错现象描述该问题原因是 调用okhttp-3.8.1.jar 这个包的方法不存在。

排查步骤1: 检查改文件是否存在

 这是使用eclipse查看jar 的引用发现该 jar 文件是存在的

排查步骤2:检查maven引入的包

到Maven Dependencies 中查找 okhttp-3.8.1.jar

 找到改包后查看来源

 

 找到这是另外一个包也引用了okhttp-3.8.1.jar 包 ,这样的话我们需要剔除多余的引用

排查步骤3:剔除多余的jar

     这里从哪个包剔除都行,最好是从后引入的包中剔除我这边是 华为云的obs做例子

        <dependency>
		   <groupId>com.huaweicloud</groupId>
		   <artifactId>esdk-obs-java</artifactId>
		   <version>[3.21.4,)</version>
		   <exclusions>
           		<exclusion>
               		 <groupId>com.squareup.okhttp3</groupId>
					 <artifactId>okhttp</artifactId>
           		</exclusion>
		   </exclusions>
		</dependency>

这样就可以剔除esdk-obs-java 中引用的  okhttp 包了。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值