Field xxx in xxx required a bean of type xxx that could not be found

背景:微服务之间使用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"})
发布了43 篇原创文章 · 获赞 13 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/qq_41070393/article/details/88812371