Sentinel version 1.8.0 (which not exists WebCallbackManager or UrlBlockHandler )
? correct demonstation
pom.xml import
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-spring-webmvc-adapter</artifactId>
<version>x.y.z</version>
</dependency>
override interface
@Configuration
public class SeckillBlockExceptionHandler implements BlockExceptionHandler {
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception {
R error = R.error(BizCodeEnum.TOO_MANY_REQUESTS);
response.setHeader("Content-Type", "application/json;charset=UTF-8");
response.getWriter().write(JSONUtil.toJsonStr(error));
}
}
response:
{"msg":"请求流量过大","code":10003}
? incorrected demonstration
addInterceptors
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fICZmsIi-1648613231456)(https://user-images.githubusercontent.com/35659194/160745594-1fa0cfd1-2a73-4959-9e6a-532ad6d2c53e.png)]
Not Exists field cause of SentinelWebMvcConfig does not exist blockExceptionHandler which belongs to its father Object (BaseWebMvcConfig).
public class SentinelWebMvcConfig extends BaseWebMvcConfig {
public static final String DEFAULT_REQUEST_ATTRIBUTE_NAME = "$$sentinel_spring_web_entry_attr";
private UrlCleaner urlCleaner;
private boolean httpMethodSpecify;
private boolean webContextUnify = true;
The offical document I have read , it is helpful for testing but not accuracy.
The UrlBlockHandler was not changed. If you’re using sentinel-spring-webmvc-adapter , you may refer to: https://github.com/alibaba/Sentinel/tree/master/sentinel-adapter/sentinel-spring-webmvc-adapter
|