java.lang.NoSuchMethodError: okhttp3.internal.Platform.log AND Exception in thread "Okhttp Dispatcher" java.lang.NoSuchFieldError: INSTANCE

java.lang.NoSuchMethodError: okhttp3.internal.Platform.log AND Exception in thread "Okhttp Dispatcher" java.lang.NoSuchFieldError: INSTANCE

请帮帮我。 我有 okhttp3 和 logging-interceptor 4.7.2 版本。当我调用 ONVIF getDeviceInformation 时,java.lang.NoSuchMethodError: okhttp3.internal.Platform.log 在 "Okhttp Dispatcher" 线程中。如果我设置 okhttp3 3.14.7 版本我有 java.lang.NoSuchFieldError: INSTANCE in "Okhttp Dispatcher" thread.

<modelVersion>4.0.0</modelVersion>

<groupId>prj.group.id</groupId>
<artifactId>art.id</artifactId>
<version>0.1.0</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.0.M4</version>
</parent>

<properties>
    <java-version>1.8</java-version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-messaging</artifactId>
        <version>5.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-websocket</artifactId>
        <version>5.2.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.bytedeco</groupId>
        <artifactId>javacv</artifactId>
        <version>1.5.2</version>
    </dependency>
    <dependency>
        <groupId>org.bytedeco</groupId>
        <artifactId>ffmpeg</artifactId>
        <version>4.2.1-1.5.2</version>
    </dependency>
    <dependency>
        <groupId>org.bytedeco</groupId>
        <artifactId>ffmpeg-platform</artifactId>
        <version>4.2.1-1.5.2</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.12</version>
    </dependency>
    <dependency>
        <groupId>be.teletask.onvif</groupId>
        <artifactId>onvif</artifactId>
        <version>1.0.2</version>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.7.2</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>logging-interceptor</artifactId>
            <version>4.7.2</version>
        </dependency>
        <dependency>
            <groupId>com.burgstaller</groupId>
            <artifactId>okhttp-digest</artifactId>
            <version>2.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.2.2.RELEASE</version>
        </plugin>
    </plugins>
</build>

<repositories>
    ***

</repositories>

<pluginRepositories>
    ***
</pluginRepositories>

调用 getDeviceInformation 时 onError 方法出错

OnvifManager manager = new OnvifManager();
manager.setOnvifResponseListener( new OnvifResponseListener() {
@Override
public void onError(OnvifDevice device, int I, String s) {
System.out.println(s);
}
...
});
...
manager.getDeviceInformation(onvifDevice, (device, information) -> {
// Don't reach this code
information.getModel();
});

I have okhttp3 and logging-interceptor 4.7.2 versions. I have java.lang.NoSuchMethodError: okhttp3.internal.Platform.log

这是一个依赖问题, 您正在使用:

  1. okhttp-4.7.2
  2. logging-interceptor-4.7.2
  3. okhttp-digest-2.0

并且 okhttp-digest-2.0 的运行时依赖是 okhttp-4.0.1

Maven 回购:https://mvnrepository.com/artifact/com.burgstaller/okhttp-digest/2.0

所以现在你有同一个库的两个不同版本

1.okhttp-4.0.1 来自 okhttp-digest-2.0

2.okhttp-4.7.2

日志函数有一个变化(这就是错误所说的NoSuchMethodError:okhttp3。internal.Platform.log)我们可以在图像中看到

解决方案:

  1. 您可以更新可以与 okhttp-4.7.2 一起使用的 okhttp-digest 版本
  2. 如果您不使用依赖它的功能,您可以从 okhttl-digest 中排除 okhttp 依赖项。

截至 2020 年 10 月 26 日,最新的 okhttp-digest v2.5 需要 okhttp v4.7.2 依赖项。

对于 okhttp-digest 的未来版本,请务必检查等效的 okhttp 依赖项。