java Spring Cloud:如何在没有 Ribbon 的情况下使用 Feign
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27620338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring Cloud: How to use Feign without Ribbon
提问by Konrad Hosemann
I would like to use Feign without client-side loadbalancer Ribbon because I don't want to run Eureka, which would need to be distributed and highly available. Instead internal ELBs with internal DNS names managed by Route53 will do just fine.
我想在没有客户端负载均衡器 Ribbon 的情况下使用 Feign,因为我不想运行 Eureka,它需要分布式和高可用性。相反,具有由 Route53 管理的内部 DNS 名称的内部 ELB 就可以了。
Providing plain URLs to @FeignClient
always results in no loadbalancer found for ..
, so I tried preventing Feign from using Ribbon:
提供纯 URL@FeignClient
总是会导致no loadbalancer found for ..
,所以我尝试阻止 Feign 使用 Ribbon:
Spring Cloud Netflix comes with FeignRibbonClient
, which is used if ILoadBalancer
from ribbon-loadbalancer
is present. However, if this dependency is excluded FeignConfiguration
is broken:
Spring Cloud Netflix 附带FeignRibbonClient
,如果ILoadBalancer
fromribbon-loadbalancer
存在则使用。但是,如果排除此依赖项会FeignConfiguration
被破坏:
Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'apiVersionClient': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: feign.codec.Decoder org.springframework.cloud.netflix.feign.FeignConfiguration.decoder; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
Ideas welcome :-)
欢迎提出想法:-)
回答by spencergibb
If you want to use a plain URL use:
如果要使用普通 URL,请使用:
@FeignClient(value = "http://example.com", loadbalance = false)
With the Brixton release train you would use:
使用 Brixton 发布系列,您将使用:
@FeignClient(url = "http://example.com", name = "example")
回答by Jason
Somewhat late, but after looking into this if you provide your own Client Bean the LoadBalancerFeignClient wont get built and used, and the Feign open tracing autoconfig will still work.
有点晚了,但是如果您提供自己的客户端 Bean,则在研究此问题之后,LoadBalancerFeignClient 将不会被构建和使用,并且 Feign 打开跟踪自动配置仍然可以工作。
@Bean
public Client feignClient() {
return new Client.Default(null, null);
}