springboot全局增加sentinel
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
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · springboot使用lock4j实现并发控制
- · Springboot整合Swagger常用注解
- · swagger隐藏authentication参数
- · Spring Security 中的自定义PreAuthorize 注解
- · JACKSON和FASTJSON处理返回JSON数据中为NULL字段不显示
- · 将数据从mysql迁移到clickhouse
- · springboot登录失败3次后需要验证码的设计及实现
- · Mybatis —— 解决单引号带来的sql注入问题
- · Springboot整合Nacos(动态改变数据库连接参数)
- · springboot访问静态资源404 —-idea设置问题
- · Java基础问题13个,你都会哪些?
- · 不重新打包项目并替换部分jar包