分类

链接

2023 年 2 月
 12345
6789101112
13141516171819
20212223242526
2728  

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > JAVA > 正文
共享办公室出租
springboot全局增加sentinel
JAVA 暂无评论 阅读(144)

pom.xml增加:

<!--sentinel-->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
<version>1.8.6</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-annotation-aspectj</artifactId>
<version>1.8.6</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-transport-simple-http</artifactId>
<version>1.8.6</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-web-servlet</artifactId>
<version>1.8.6</version>
</dependency>
<!--sentinel end-->

 

 

代码增加config bean:

import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.Filter;
@Configuration
publicclassSentinelConfig{
@Bean
publicSentinelResourceAspect sentinelResourceAspect(){
returnnewSentinelResourceAspect();
}
@Bean
publicFilterRegistrationBean sentinelFilterRegistration(){
FilterRegistrationBean<Filter> registration =newFilterRegistrationBean<>();
        registration.setFilter(newCommonFilter());
        registration.addUrlPatterns("/api/*");
        registration.setName("sentinelFilter");
        registration.setOrder(1);
return registration;
}
}

 

相关官方文档:

https://sentinelguard.io/zh-cn/docs/annotation-support.html

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:springboot全局增加sentinel | Bruce's Blog

发表评论

留言无头像?