前言 最近在将原有的单体SpringBoot项目搬迁至SpringCloud的时候出现了启动项目miNIO报错的问题。 Error creating bean with name ‘minioclient’ defined in class
最近在将原有的单体SpringBoot项目搬迁至SpringCloud的时候出现了启动项目miNIO报错的问题。
Error creating bean with name ‘minioclient’ defined in class path resource [com/ruoyi/clockin_v2/config/MinioConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.minio.MinioClient]: Factory method ‘minioClient’ threw exception; nested exception is java.lang.NoSuchFieldError: Companion
之前在启动单体springboot的时候并未出现这个问题,经过bean注册的过程发现是在使用okHttp3的HttpUrl.parse(url)的时候报的错
(通过代码的追踪发现是在执行endpoint的时候调用如下的HttpUrl.parse(endpoint);报错了)
@Bean public MinioClient minioClient() { HttpUrl parse = HttpUrl.parse(url); System.out.println(parse.url()); return MinioClient.builder().endpoint(url).credentials(accessKey, secreTKEy).build(); }通过代码的追踪发现是在执行endpoint的时候调用如下的HttpUrl.parse(endpoint);报错了。所以可以确定是okhttp出现的问题private HttpUrl getBaseUrl(String endpoint) { this.validateNotEmptyString(endpoint, "endpoint"); HttpUrl url = HttpUrl.parse(endpoint); if (url == null) { this.validateHostnameOrIPAddress(endpoint); url = (new HttpUrl.Builder()).scheme("https").host(endpoint).build(); } else { this.validateUrl(url); } return url;}
然后通过Maven依赖可以看到minio里面okhttp版本为4.8.1,但是实际的版本是使用的4.9.3,这是因为项目的springboot依赖的是okhttp的4.9.3的版本
通过以前正常启动项目的追踪,发现minio的正常启动的okhttp的版本为3.14.9
解决方式
将minio的依赖版本设置为3.14.9即可
<!-- minio工具包 --> <dependency> <groupId>io.minio</groupId> <artifactId>minio</artifactId> <version>${minio.version}</version> </dependency> <!-- 解决minio使用okhttp高版本的时候注入bean实例报错的问题 --> <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>3.14.9</version> <scope>compile</scope> </dependency>
--结束END--
本文标题: 解决springboot启动时minio报错的问题(注入bean时报错)
本文链接: https://www.lsjlt.com/news/375269.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-03
2024-04-03
2024-04-01
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0