sentinel报错:field private java.util.Optional com.alibaba.cloud.sentinel.SentinelWebAutoConfiguration
Sentinel
alibaba/Sentinel: Sentinel 是阿里巴巴开源的一款面向分布式服务架构的流量控制、熔断降级组件,提供实时监控、限流、降级和系统保护功能,适用于微服务治理场景。
项目地址:https://gitcode.com/gh_mirrors/sentine/Sentinel

·
错误说明
使用2021.1版的spring-cloud-alibaba时,如果启用了sentinel作为流控、降级服务,启动的时候会报错误:
The dependencies of some of the beans in the application context form a cycle:
com.alibaba.cloud.sentinel.SentinelWebAutoConfiguration (field private java.util.Optional com.alibaba.cloud.sentinel.SentinelWebAutoConfiguration.sentinelWebInterceptorOptional)
这个报错其实很明显了,就是sentinel下的某一个类,循环依赖了(A中注入了B,B中也注入了A), 原因就是新版本的Spring默认不允许循环依赖!
解决方案
方式一:把enabled设为false(不推荐)
spring.cloud.sentinel.enabled默认是启用状态,为true,把它设为false之后就是不启用了。这样确实是不报循环依赖的错误了,但是项目中也没有使用sentinel了
spring:
cloud:
sentinel:
enabled: false
transport:
dashboard: 127.0.0.1:20059
port: 8719
方式二:配置允许循环依赖(推荐)
修改Spring的配置,设置允许循环依赖,把spring.main.allow-circular-references设为true
spring:
application:
name: ms-demo
profiles:
active: dev
#允许循环依赖
main:
allow-circular-references: true




alibaba/Sentinel: Sentinel 是阿里巴巴开源的一款面向分布式服务架构的流量控制、熔断降级组件,提供实时监控、限流、降级和系统保护功能,适用于微服务治理场景。
最近提交(Master分支:30 天前 )
4a419818
* Improved Date formatter
* change in naming conv
* change in datetime format
* Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> 22 天前
d9398b4f
23 天前
更多推荐
所有评论(0)