Field client in com.rachel.web.ConsumerController required a bean of type 'org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient' that could not be found.

在启动一台消费者微服务时出现了异常

Field client in com.rachel.web.ConsumerController required a bean of type 'org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient' that could not be found.

意思是找不到这个bean RibbonLoadBalancerClient

应该是没注入到容器中,检查controller,发现了编译前异常

 这个bean没注入,但为什么呢?

解决方式:将RibbonLoadBalancerClient修改为 LoadBalancerClient

原因:

我们的需求是用给RestTemplate加一个ribbon的客户端,让它在发起请求时拥有负载均衡能力

查看@LoadBalanced源码,有一行注释,意思是:这个注解用来给RestTemplate配置使用一个LoadBalancerClient

所以,我们在controller中注入的时候应该注入这个客户端

 那到底RibbonLoadBalancerClient和LoadBalancerClient有什么区别呢?

 原来前者是后者的实现类



原文地址:https://www.cnblogs.com/rachelgarden/p/13022444.html