Sentinel整合OpenFeign时出现循环依赖解决(Is there an unresolvable circular reference?)

错误信息

在OpenFeign整合Sentinel的时候出现循环依赖的报错

Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException:Error creating bean with name 'top.mowang.cloud.service.PaymentService': Requested bean is currently in creation: Is there an unresolvable circular reference?

环境信息

Spring Cloud和Spring Cloud Alibaba版本信息:

<!--spring cloud Hoxton.SR12-->
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-dependencies</artifactId>
	<version>Hoxton.SR12</version>
	<type>pom</type>
	<scope>import</scope>
</dependency>
<!--spring cloud alibaba 2.1.0.RELEASE-->
<dependency>
	<groupId>com.alibaba.cloud</groupId>
	<artifactId>spring-cloud-alibaba-dependencies</artifactId>
	<version>2.2.1.RELEASE</version>
	<type>pom</type>
	<scope>import</scope>
</dependency>

我是在当前OpenFeign能成功整合Hystrix的前提下进行和Sentinel整合

在开启Sentinel对Feign的支持的配置后在启动时就出现了循环依赖的问题

开启Sentinel对Feign的支持:

feign:
  sentinel:
    enabled: true

PaymentService类:

@FeignClient(value = "nacos-payment-provider",fallback = PaymentFallbackService.class)
public interface PaymentService {
    @GetMapping(value = "/paymentSQL/{id}")
    public CommonResult<Payment> paymentSQL(@PathVariable("id") Long id);
}

PaymentService在注入到controller出现了循环依赖

问题原因和目前的解决方案

问题出在Spring Cloud和Spring Cloud Alibaba的版本上,具体就是Sentinel和OpenFeign版本兼容问题,目前的解决方案就是切换为兼容的版本,等待官方修复,在将spring cloud版本为Hoxton.SR3,spring cloud alibaba版本为2.1.0.RELEASE后正常启动,问题解决

<!--spring cloud Hoxton.SR3-->
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-dependencies</artifactId>
	<version>Hoxton.SR3</version>
	<type>pom</type>
	<scope>import</scope>
</dependency>
<!--spring cloud alibaba 2.1.0.RELEASE-->
<dependency>
	<groupId>com.alibaba.cloud</groupId>
	<artifactId>spring-cloud-alibaba-dependencies</artifactId>
	<version>2.2.1.RELEASE</version>
	<type>pom</type>
	<scope>import</scope>
</dependency>

作者(Author):魔王Dany
链接(URL):https://mowangblog.top/mowang/sentinel
来源(Source):魔王の博客

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值