sentinel引入CommonFilter类

最近在做一个springcloudAlibaba项目,做链路流控模式时需要将入口资源关闭聚合,做法如下:

spring-cloud-alibaba v2.1.1.RELEASE及前,sentinel1.7.0及后:

1.pom 中引入:

java 复制代码
<dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-web-servlet</artifactId>
            <version>1.8.0</version>
</dependency>

2.添加一下配置:

java 复制代码
package com.atguigu.springcloud.config;


import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterContextConfig {
    @Bean
    public FilterRegistrationBean sentinelFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new CommonFilter());
        registration.addUrlPatterns("/*");
        // 入口资源关闭聚合
        registration.addInitParameter(CommonFilter.WEB_CONTEXT_UNIFY, "false");
        registration.setName("sentinelFilter");
        registration.setOrder(1);
        return registration;
    }
}

spring-cloud-alibaba v2.1.1.RELEASE后:

配置文件添加:

spring.cloud.sentinel.web-context-unify=false

相关推荐
yoyo_zzm2 天前
SpringCloud Gateway 集成 Sentinel 详解 及实现动态监听Nacos规则配置实时更新流控规则
spring cloud·gateway·sentinel
短剑重铸之日3 天前
深入理解Sentinel: 01 一次服务雪崩问题排查经历
java·sentinel·降级熔断
列星随旋5 天前
sentinel
sentinel
zz0723205 天前
阿里开源流量防护组件——Sentinel
sentinel
weixin199701080166 天前
《淘宝双11同款:基于 Sentinel 的微服务流量防卫兵实战》
微服务·架构·sentinel
一叶飘零_sweeeet7 天前
高可用架构核心:限流熔断降级全解,Sentinel 与 Resilience4j 原理 + 落地实战
架构·sentinel
Fang fan10 天前
Redis基础数据结构
数据结构·数据库·redis·缓存·bootstrap·sentinel
回到原点的码农11 天前
SpringCloud Gateway 集成 Sentinel 详解 及实现动态监听Nacos规则配置实时更新流控规则
spring cloud·gateway·sentinel
没有bug.的程序员12 天前
黑客僵尸网络的降维打击:Spring Cloud Gateway 自定义限流剿杀 Sentinel 内存黑洞
java·网络·spring·gateway·sentinel