最近在做一个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