记录一次springboot接入Sentinel的问题

目录

引入pom

配置JVM启动参数

报错解决 


引入pom

这是官方指定的方式,springboot需要引入

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    <version>2.1.2.RELEASE</version>
</dependency> 

除了这个还需要引入core包和sentinel客户端与dashboard通信包,不引入无法注册到dashboard上

        <!--阿里的限流工具 sentinel-->
        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-core</artifactId>
            <version>1.8.0</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-annotation-aspectj</artifactId>
            <version>1.8.0</version>
        </dependency>
        <!-- sentinel客户端与dashboard通信依赖 -->
        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-transport-simple-http</artifactId>
            <version>1.8.0</version>
        </dependency>

 这个时候,如果报错,说明有两个类相互引用对方,导致Spring在初始化bean的时候不知道先初始化哪个,从而形成循环依赖注入。

修改方式。yaml文件加上

spring:
  main:
    allow-circular-references: true

配置JVM启动参数

启动参数需要加

java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard.jar

也可以在yaml这么配,具体可以百度

这个时候就可以注册成功,在dashboard种看到你的服务,进行下一步操作

报错解决 

1、ClassNotFoundException com.alibaba.csp.sentinel.spi.ServiceLoaderUtil in version 1.8.1

这个其实不影响使用,是因为报缺少依赖,在github上有大佬已经给出解决了,只用替换对的版本,我使用的是1.8.0的,就没问题

ClassNotFoundException com.alibaba.csp.sentinel.spi.ServiceLoaderUtil in version 1.8.1 · Issue #2111 · alibaba/Sentinel · GitHub 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值