alibaba / Sentinel

A powerful flow control component enabling reliability, resilience and monitoring for microservices. (面向云原生微服务的高可用流控防护组件)
https://sentinelguard.io/
Apache License 2.0
22.36k stars 8.02k forks source link

Spring Cloud Alibaba Sentinel整合OpenFeign报循环依赖异常 #2576

Closed colddew closed 2 years ago

colddew commented 2 years ago

Spring Cloud Alibaba Sentinel整合OpenFeign会报如下循环依赖异常,网上各个版本都有类似兼容性问题,除了降低Spring Cloud的版本还有其它更好的解决方案吗?

<spring-boot.version>2.6.3</spring-boot.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
<spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
2022-02-17 16:05:18.173 ERROR 42214 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The dependencies of some of the beans in the application context form a cycle:

   org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration
┌─────┐
|  com.alibaba.cloud.sentinel.SentinelWebAutoConfiguration (field private java.util.Optional com.alibaba.cloud.sentinel.SentinelWebAutoConfiguration.sentinelWebInterceptorOptional)
└─────┘

Action:

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

Process finished with exit code 1
sczyh30 commented 2 years ago

Refer https://github.com/alibaba/spring-cloud-alibaba/issues/2330

colddew commented 2 years ago

看到兼容性矩阵了,但感觉为了使用sentinel要给springboot降版本不太合理,建议官方尽快升级吧,resilience4j的兼容性似乎要做的更好

liangyao375 commented 2 years ago

看到兼容性矩阵了,但感觉为了使用sentinel要给springboot降版本不太合理,建议官方尽快升级吧,resilience4j的兼容性似乎要做的更好

可以先在springboot配置文件中设置允许循环引用

spring.main.allow-circular-references=true

colddew commented 2 years ago

看到兼容性矩阵了,但感觉为了使用sentinel要给springboot降版本不太合理,建议官方尽快升级吧,resilience4j的兼容性似乎要做的更好

可以先在springboot配置文件中设置允许循环引用

spring.main.allow-circular-references=true

试验服务可以正常启动了,但暂时还不确定会不会引起其它的副作用

sczyh30 commented 2 years ago

Maybe this has been fixed with https://github.com/alibaba/spring-cloud-alibaba/releases/tag/2021.0.1.0