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.<clinit>(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的版本号

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <youlai.version>2.0.0</youlai.version>
        
        <!-- 覆盖SpringBoot中okhttp3的旧版本声明,解决MinIO 8.3.x的依赖冲突 -->
        <okhttp3.version>4.8.1 </okhttp3.version>
    </properties
posted @ 2022-04-09 14:35  有来技术  阅读(2647)  评论(0编辑  收藏  举报