当前位置:Gxlcms > 数据库问题 > 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.

时间:2021-07-01 10:21:17 帮助过:186人阅读

意思是找不到这个bean RibbonLoadBalancerClient

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

技术图片

 

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

解决方式:将RibbonLoadBalancerClient修改为 LoadBalancerClient

原因:

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

技术图片

 

 

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

技术图片

 

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

技术图片

 

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

技术图片

 

 原来前者是后者的实现类

 

 

 


 

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

标签:bsp   not   lan   pre   net   nbsp   balance   web   ffffff   

人气教程排行