最近在做一个springcloudAlibaba项目,做链路流控模式时需要将入口资源关闭聚合,做法如下:
spring-cloud-alibaba v2.1.1.RELEASE及前,sentinel1.7.0及后:
1.pom 中引入:
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-web-servlet</artifactId>
<version>1.8.0</version>
</dependency>
2.添加一下配置:
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后:文章来源:https://www.toymoban.com/news/detail-633036.html
配置文件添加:
spring.cloud.sentinel.web-context-unify=false文章来源地址https://www.toymoban.com/news/detail-633036.html
到了这里,关于sentinel引入CommonFilter类的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!