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