现象启动时报错:
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 包了。