: Injection of resource dependencies failed;启动微服务调用Feign,循环依赖问题

springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'cn.itcast.feign.clients.UserClient': Requested bean is currently in creation: Is there an unresolvable circular reference?

在进行Sentinel的隔离熔断测试中,我单独抽出Feign模块以做微服务之间的调用。

编写失败降级逻辑,

@Slf4j
public class UserClientFallbackFactory implements FallbackFactory<UserClient> {
    @Override
    public UserClient create(Throwable throwable) {
        return new UserClient() {
            @Override
            public User findById(Long id) {
                log.error("查询用户异常",throwable);
                return new User();
            }
        };
    }
}

在UserClient接口添加

@FeignClient(value = "userservice",fallbackFactory = UserClientFallbackFactory.class)

 在Config类自动注册Bean

 @Bean
    public UserClientFallbackFactory userClientFallbackFactory(){
        return new UserClientFallbackFactory();
    }

但在启动OrderApplication时出现了如首段的错误,后发现可能是启动类未能扫描到FeingClient的内容于是我在OrderApplication启动类添加如下代码

@ComponentScan("cn.itcast.feign")

启动成功! 

但是Order/101又打不开了。于是我又翻天倒地的,最后尝试更换Springcloud版本将SR10换成9,虽然版本号爆红,但不影响启动!

<spring-cloud.version>Hoxton.SR9</spring-cloud.version>

 实现了Feign与Sentinel的整合。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值