在啟動一台消費者微服務時出現了異常
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有什么區別呢?
原來前者是后者的實現類