本质上就是导入的依赖中出现了重名,ioc进行注入的时候会根据名字来,这样的话就会遭成依赖冲突,我的错误是
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'connectionManager' defined in class path resource [org/springframework/cloud/openfeign/clientconfig/HttpClientFeignConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.cloud.openfeign.clientconfig.HttpClientFeignConfiguration; factoryMethodName=connectionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/cloud/openfeign/clientconfig/HttpClientFeignConfiguration.class]] for bean 'connectionManager': There is already [Generic bean: class [com.github.tobato.fastdfs.domain.conn.ConnectionManager]; scope=singleton; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [jar:file:/D:/Apps/Learn/Maven3.8.8/apache-maven-3.8.8/repository/com/github/tobato/fastdfs-client/1.26.5/fastdfs-client-1.26.5
这个错误信息表明在Spring容器中存在名为connectionManager的bean定义冲突。具体来说,错误信息中提到了在HttpClientFeignConfiguration类中定义了名为connectionManager的bean,而在其他位置(fastdfs-client-1.26.5.jar中)也存在相同名称的connectionManager的bean。
解决方法:
配置文件添加
YAML
#yaml 这里演示格式
spring:
main:
allow-bean-definition-overriding: true