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有什么区别呢?

 

 原来前者是后者的实现类

 

 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 springcloud 项目搭建遇到的问题及解决-Field restTemplate in com.cloud.ribbon_consumer.project.service.xxxService required a bean of type 'org.springframework.web.client.RestTemplate' that could not be found. Field redisTemplate in xxxxxx required a bean of type 'org.springframework.data.redis.core.RedisTemplate' that could not be found. Spring Cloud Ribbon负载均衡配置类放在Spring boot主类同级增加Exclude过滤后报Field config in com.cloud.web.controller.RibbonConfiguration required a bean of type 'com.netflix.client.config.IClientConfig' that could not b SpringCloud报错: "Field discoveryClient in com.controller.DcController required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found." Controller required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found.异常处理 Springboot 问题: required a bean of type 'org.springframework.scheduling.TaskScheduler' that could not be found. Field xxxMapper in xxxxxxx required a bean of type 'xxxxMapper'that could not be found. 2. springboot启动报错:Field userMapper in com.service.UserService required a bean of type 'com.dao.UserMapper' that could not be found. 报错:java.lang.AbstractMethodError: org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.choose(Ljava/lang/String;Lorg/springframework/cloud/client/loadbalancer/Request;)Lorg/spring Sping Cloud项目启动报A component required a bean of type 'com.tianyan.bbc.dao.SecurityUserBaseMapper' that could not be found.
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM