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的整合。