問題的表現很明顯,就是在spring容器中找不到被@FeignClient標註類的實例:spring
*************************** APPLICATION FAILED TO START *************************** Description: Field xxxClient in xxx包 required a bean of type 'xxxClient' that could not be found. Action: Consider defining a bean of type 'xxxClient' in your configuration.
形成上述異常的緣由很明顯,在spring容器中找不到對應的實例。ide
被@FeignClient標註的類,在容器初始化的時候會生成對應的代理的,若是沒有生成,說明spring沒有掃描到該類。因此在啓動類上加上 @EnableFeignClients 便可。ui
但有的狀況下,只加@EnableFeignClients也是掃描不到的,好比說,你的項目是多模塊,包名不一樣,因此掃描不到,這樣能夠在註解中指定 basePackages:代理
@EnableFeignClients(basePackages = "xxx.proxy") public class xxxApplication { public static void main(String[] args) { SpringApplication.run(xxxApplicationn.class, args); } }
意思是掃描指定包路徑下的 帶有 @FeignClient 的類。code
若是你的 @EnableFeignClients 飄紅引用不到,那你必定是引用錯包了,對於SpringBoot這邊建議引用starter:ip
<!-- feign --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>