SpringBoot集成MinIO8.3.x 依赖冲突解决,至简之招覆盖spring-boot-dependencies的依赖版本声明
版本声明
-
SpringBoot 2.6.5
-
MinIO 8.3.7
报错信息
An attempt was made to call a method that does not exist. The attempt was made from the following location:
io.minio.S3Base.(S3Base.java:98)
The following method did not exist:
okhttp3.RequestBody.create([BLokhttp3/MediaType;)Lokhttp3/RequestBody;
The calling method's class, io.minio.S3Base, was loaded from the following location:
jar:file:/D:/Soft/apache-maven-3.8.4/repository/io/minio/minio/8.3.7/minio-8.3.7.jar!/io/minio/S3Base.class
The called method's class, okhttp3.RequestBody, is available from the following locations:
jar:file:/D:/Soft/apache-maven-3.8.4/repository/com/squareup/okhttp3/okhttp/3.14.9/okhttp-3.14.9.jar!/okhttp3/RequestBody.class
报错分析
点开minio的pom.xml 查看okhttp 声明版本是 4.8.1,但报错提示的版本是 3.14.9,这个版本是 spring-boot-dependencies-2.6.5.xml 声明的,所以只要覆盖springboot默认声明的okhttp3版本。
解决方案
在父工程pom.xml里修改properties的版本号
org.springframework.boot
spring-boot-starter-parent
2.6.5
2.0.0
4.8.1