- maven最新坐标
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
</dependencies>
- 业务降级处理接口变化
UrlBlockHandler
->BlockExceptionHandler
- 配置变化 WebCallbackManager被删除 只需要创建 BlockExceptionHandler 接口实现类即可实现自动配置
@Configuration
public class SentinelConfig {
@Bean
public BlockExceptionHandler sentinelBlockExceptionHandler() {
return (request, response, e) -> {
// 429 Too Many Requests
response.setStatus(429);
PrintWriter out = response.getWriter();
out.print("Oops, blocked by Sentinel: " + e.getClass().getSimpleName());
out.flush();
out.close();
};
}
}
- 参考官方demo