记录一次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 

猜你喜欢

转载自blog.csdn.net/qq_37761711/article/details/129855332