背景:微服务之间使用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"})

本文介绍了解决微服务间使用Feign调用时启动报错的问题。通过正确配置@EnableFeignClients和@ComponentScan注解,确保所有依赖的服务都能被正确扫描到。
3568

被折叠的 条评论
为什么被折叠?



