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

相关推荐
Owen__z20 小时前
GEE统计特定区域特定时间上的Landsat/Sentinel的影像信息
python·sentinel·gee·geemap·landsat
我要去腾讯21 小时前
Springcloud核心组件之Sentinel详解
java·spring cloud·sentinel
哦你看看6 天前
Redis Sentinel哨兵集群
linux·redis·bootstrap·sentinel
2501_938790077 天前
Spring Cloud Alibaba 2023 版:Nacos 服务发现与 Sentinel 限流的整合方案
sentinel·服务发现
青鱼入云7 天前
Sentinel介绍
微服务·sentinel
青鱼入云7 天前
Feign如何集成Sentinel
spring cloud·微服务·sentinel
一周困⁸天.9 天前
Redis Sentinel哨兵集群
redis·bootstrap·sentinel
一条懒鱼6669 天前
Redis Sentinel哨兵集群
数据库·redis·sentinel
2301_7976042410 天前
d44:Sentinel 微服务流量控制与 Seata 分布式事务
分布式·微服务·sentinel
新手小白*10 天前
Redis Sentinel哨兵集群
数据库·redis·sentinel