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

2021/11/4 23:41:22

本文主要是介绍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):魔王の博客



这篇关于Sentinel整合OpenFeign时出现循环依赖解决(Is there an unresolvable circular reference?)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程