解决办法在最后
SpringBoot引入okHttp3
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
报错
2024-08-17 14:50:41.541 ERROR --- [http-nio-3001-exec-1] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] log 175 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Filter execution threw an exception] with root cause
java.lang.NoSuchMethodError: kotlin.collections.ArraysKt.copyInto([B[BIII)[B
at okio.Segment.writeTo(Segment.kt:169)
at okio.Segment.compact(Segment.kt:152)
at okio.Buffer.write(Buffer.kt:1491)
at okio.Buffer.read(Buffer.kt:1503)
at okio.Buffer.writeAll(Buffer.kt:1290)
at okio.Options$Companion.buildTrieRecursive(Options.kt:189)
at okio.Options$Companion.buildTrieRecursive(Options.kt:175)
at okio.Options$Companion.buildTrieRecursive$default(Options.kt:107)
at okio.Options$Companion.of(Options.kt:72)
at okhttp3.internal.Util.<clinit>(Util.kt:70)
at okhttp3.internal.concurrent.TaskRunner.<clinit>(TaskRunner.kt:309)
at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:41)
at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:47)
at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.kt:471)
排查发现,项目中引入的包和pom文件中的包版本并不一致!!!!!!
okhttp3中引入的包
项目汇总的包:
排查发现,是因为SpringBoot中内置的版本号和okhttp3中的不一致导致的,且是以SpringBoot中的优先。
解决办法:
在父pom文件中引入这两个包,就不会用SpringBoot内置版本的包了
这两个包,从你引入的okhttp中找。版本号和我这个不一定一样
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.6.20</version>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio-jvm</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>