背景:微服务之间使用Feign调用,当微服务B依赖微服务A后,启动报错Field xxx in xxx required a bean of type xxx that could not be found
使用@SpringCloudApplication+@ComponentScan或@SpringBootApplication+@EnableEurekaClient注解均会报错(包没扫描到)
解决办法:
使用@EnableFeignClients(basePackages={"com.xxx.xxx"})
方案一:(SpringBootApplication配置scanBasePackages = "xxxx")自行加上
@SpringBootApplication
@EnableFeignClients(basePackages={"com.xxx.xxx","com.xx.xxx"})
方案二:
@SpringCloudApplication
@ComponentScan(basePackages = {
"com.xxx.lib",
"com.xxx.xxx",
"com.xxx.xxxx"})
@EnableFeignClients(basePackages = {"com.xxx.xxx","com.xx.xxx"})