在搭建spring cloud微服务时经常会遇到如下错误:
Description:
Field orderInfoFeignClient in com.mcu.stock.service.StockService required a bean of type 'com.mcu.common.feign.order.OrderInfoFeignClient' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.mcu.common.feign.order.OrderInfoFeignClient' in your configuration.就是feignclient扫瞄不到,在启动类上也加了@EnableFeignClients,也没用,甚至加了@ComponentScan("com.mcu")这样的配置也没用。代码如下:
@EnableEurekaClient
@SpringBootApplication
@EnableFeignClients
@ComponentScan("com.mcu")
public class McuOrderApplication
{
public static void main(String[] args) {
SpringApplication.run

在Spring Cloud微服务中遇到FeignClient无法找到的错误,即使使用@EnableFeignClients和@ComponentScan也无效。解决方法是在项目初期规划清晰的包结构,例如将common模块的代码放在如'com.mcu.common.feign'等包下,而业务模块按'com.mcu.controller','com.mcu.service'等划分。启动类置于顶级包'com.mcu',这样无需额外配置,Spring Boot会自动扫描所有子包内的FeignClient。
最低0.47元/天 解锁文章
8449

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



