openfeign与gateway中的httpClient类声明冲突

自古美人都是妖i 提交于 2020-05-08 00:41:46

<div class="contentDiv" style="color:#333333"><p><span style="font-size:16px;">启动spring cloud中的网关,报错:</span></p><p><span style="font-size:16px;">***************************<br>APPLICATION FAILED TO START<br>***************************<br><br>Description:<br><br>The bean 'httpClient', defined in class path resource [org/springframework/cloud/openfeign/ribbon/HttpClientFeignLoadBalancedConfiguration$HttpClientFeignConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/cloud/gateway/config/GatewayAutoConfiguration$NettyConfiguration.class] and overriding is disabled.<br><br>Action:<br><br>Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true<br></span></p><p><span style="font-size:16px;">我用的网关是gateway,内部调用是用的openfeign,这两者会冲突,上面报错信息显示httpClient在两者都有声明,要把两者中一者去掉,于是看了下两个类的源码,可以把feign上的httpClient禁用了。</span></p><p><span style="font-size:16px;">org/springframework/cloud/openfeign/ribbon/HttpClientFeignLoadBalancedConfiguration$HttpClientFeignConfiguration.class的代码中有如下图:<br></span></p><p><span style="font-size:16px;"><img src="https://img2018.cnblogs.com/blog/1112483/201911/1112483-20191121170324082-1583384292.png" alt=""><br></span></p><p><span style="font-size:16px;">上面可以看出,可以配置:</span></p><p><span style="font-size:16px;">feign.httpclient.enabled=false<br></span></p><p><span style="font-size:16px;">或者</span></p><p><span style="font-size:16px;">feign.compression.response.enabled=true<br></span></p><p><span style="font-size:16px;">来禁用openfeign的httpClient类定义</span></p><p><span style="font-size: 16px;">也可以直接用配置:<span style="color: rgb(51, 51, 51); font-family: 微软雅黑; font-size: 16px;">spring.main.allow-bean-definition-overriding=true&nbsp;</span><br></span></p>原文地址:http://www.classinstance.cn/detail/53.html</div>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!