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

青旅半醒 2022-02-28 14:42 405阅读 0赞

背景:微服务之间使用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”)自行加上

  1. @SpringBootApplication
  2. @EnableFeignClients(basePackages={"com.xxx.xxx","com.xx.xxx"})

方案二:

  1. @SpringCloudApplication
  2. @ComponentScan(basePackages = {
  3. "com.xxx.lib",
  4. "com.xxx.xxx",
  5. "com.xxx.xxxx"})
  6. @EnableFeignClients(basePackages = {"com.xxx.xxx","com.xx.xxx"})

发表评论

表情:
评论列表 (有 0 条评论,405人围观)

还没有评论,来说两句吧...

相关阅读