minio8.3.5依赖冲突

SpringCloud中导入依赖minio8.3.5和okhttp4.9.0依赖,启动时报错:

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:105)
The following method did not exist:    okhttp3.RequestBody.create([BLokhttp3/MediaType;)Lokhttp3/RequestBody;

.........
Action:
Correct the classpath of your application so that it contains a single, compatible version of okhttp3.RequestBody

场景:微服务cloud-common-oss模块中,导入了依赖minio8.3.5,okhttp4.9.0

<dependency>
	<groupId>io.minio</groupId>
	<artifactId>minio</artifactId>
    <version>8.3.5</version>
    <exclusions>
    	<exclusion>
          	<artifactId>okhttp</artifactId>
            <groupId>com.squareup.okhttp3</groupId>
         </exclusion>
    </exclusions>
</dependency>
<dependency>
	<groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
	<version>4.9.0</version>
</dependency>

minio中本身封装了okhttp依赖,但版本不合适,于是添加<exclusions>将其封装的okttp排除。并添加4.9.0版本的okhttp依赖。

在微服务cloud-app-park中调用了cloud-common-oss的minioService相关接口,启动cloud-app-park时一直报okhttp依赖冲突。
先检查cloud-common-oss中pom.xml以及其父pom是否存在okhttp的冲突版本,
可查看pom.xml的依赖图
在这里插入图片描述
Ctrl+鼠标上翻键放大依赖关系图;Ctrl+F搜索依赖名称。可以看到只存在一个okhttp4.9.0版本。
在这里插入图片描述
但确保cloud-common-oss中只有一个okhttp4.9.0版本后,启动cloud-app-park时,还是报冲突问题:
打开cloud-app-park模块的依赖关系图发现,该图中显示cloud-common-oss的okhttp还是3.14.4版本的。

解决:在cloud-app-park的pom.xml中引入依赖okhttp.4.9.0版本:

<dependency>
	<groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
	<version>4.9.0</version>
</dependency>

注意:当cloud-common-oss的pom.xml文件发生改变,其模块需要执行一下clean,compile,install。并且引入该模块的的模块也要执行cleancompile命令。

mvn clean
mvn compile
mvn install

另一种依赖版本管理方法解决:
父pom.xml:

<properties>
	<minio.version>8.3.5</minio.version>    																																
	<okhttp.version>4.9.0</okhttp.version>
</properties>

    <!-- 依赖声明 -->
    <dependencyManagement>
        <dependencies>
        ...
           <dependency>
                <groupId>io.minio</groupId>
                <artifactId>minio</artifactId>
                <version>${minio.version}</version>
            </dependency>
            <dependency>
                <groupId>com.squareup.okhttp3</groupId>
                <artifactId>okhttp</artifactId>
                <version>${okhttp.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

cloud-common-oss的pom.xml:

<dependency>
	<groupId>io.minio</groupId>
    <artifactId>minio</artifactId>
   	<exclusions>
    	<exclusion>
            <artifactId>okhttp</artifactId>
        	<groupId>com.squareup.okhttp3</groupId>
        </exclusion>
   	</exclusions>
</dependency>
<dependency>
	<groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
</dependency>
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值