openfeign与gateway中的httpClient类声明冲突

原创 2019-07-06 12:27 阅读(3025)次

启动spring cloud中的网关,报错:

***************************
APPLICATION FAILED TO START
***************************

Description:

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.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

我用的网关是gateway,内部调用是用的openfeign,这两者会冲突,上面报错信息显示httpClient在两者都有声明,要把两者中一者去掉,于是看了下两个类的源码,可以把feign上的httpClient禁用了。

org/springframework/cloud/openfeign/ribbon/HttpClientFeignLoadBalancedConfiguration$HttpClientFeignConfiguration.class的代码中有如下图:


上面可以看出,可以配置:

feign.httpclient.enabled=false

或者

feign.compression.response.enabled=true

来禁用openfeign的httpClient类定义

也可以直接用配置:spring.main.allow-bean-definition-overriding=true