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

相关推荐
power-辰南2 天前
基于 Spring Cloud + Sentinel 的全面流量治理方案
spring·spring cloud·sentinel·流量治理
蔚一3 天前
微服务SpringCloudAlibaba组件sentinel教程【详解sentinel的使用以及流量控制、熔断降级、热点参数限流等,附有示例+代码】
java·spring boot·后端·微服务·架构·sentinel·intellij-idea
华农第一蒟蒻3 天前
Sentinel
java·开发语言·sentinel
qw9494 天前
Redis 09章——哨兵(sentinel)
数据库·redis·sentinel
FG.4 天前
微服务保护---Sentinel
微服务·sentinel
Xwzzz_5 天前
SpringCloud中Sentinel基础场景和异常处理
java·spring cloud·sentinel
bing_1585 天前
Springboot 中如何使用Sentinel
spring boot·sentinel
power-辰南7 天前
微服务限流策略与性能优化全解析
性能优化·sentinel·springcloud·流量监控·流量治理
WeiLai11129 天前
Redis Sentinel(哨兵)模式介绍
redis·bootstrap·sentinel
励碼10 天前
解决 Sentinel 控制台无法显示 OpenFeign 资源的问题
spring boot·spring cloud·sentinel·bug·openfeign