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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章