一、概述
一直以来,公司的文件上传、下载功能大部分都是使用fastdfs作为文件存储方式,少量使用了oss,本地存储以及其他一些类似oss的存储服务,但这些功能都是分散到每个系统里面单独维护,这种方式维护工作量大。于是乎准备将这些功能整合为一个文件供多个场景使用。主要使用openfeign作为微服务间的访问工具,fastdfs作为文件存储服务。代码写好后启动失败。
二、问题描述
1、系统使用的两个核心包
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
启动报错内容:The bean 'connectionManager', defined in class path resource [org/springframework/cloud/openfeign/FeignAutoConfiguration$HttpClientFeignConfiguration.class], could not be registered. A bean with that name has already been defined in URL [jar:file:/D:/maven/ldyx/repository/com/github/tobato/fastdfs-client/1.26.6/fastdfs-client-1.26.6.jar!/com/github/tobato/fastdfs/domain/conn/ConnectionManager.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
2、大概意思是openfeign和tobato两个依赖包中的connectionManager这个bean名字冲突了,可尝试通过配置spring.main.allow-bean-definition-overriding=true解决。尝试后发现没用
三、解决方案
1、经过多方查找资料发现openfeign可以使用两种方式发起http接口调用分别是httpclient和okhttp,默认是httpclient,就是这个和tobato包冲突了。解决方案如下
2、yml文件中添加如下配置:
feign:
httpclient:
enabled: false
okhttp:
enabled: true