Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
spring-cloud-timeloit
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
loit-Infrastructure-example
spring-cloud-timeloit
Commits
4c590ec1
提交
4c590ec1
authored
9月 02, 2020
作者:
陈世营
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[修改] timeloit 自定义异常
上级
513f08c9
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
42 行增加
和
1 行删除
+42
-1
SentinelWebAutoConfiguration.java
.../alibaba/cloud/sentinel/SentinelWebAutoConfiguration.java
+5
-1
CustomBlockExceptionHandler.java
.../cloud/sentinel/timeloit/CustomBlockExceptionHandler.java
+27
-0
README.md
...c/main/java/com/alibaba/cloud/sentinel/timeloit/README.md
+10
-0
没有找到文件。
spring-cloud-timeloit-starters/spring-cloud-starter-timeloit-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelWebAutoConfiguration.java
浏览文件 @
4c590ec1
...
...
@@ -18,6 +18,7 @@ package com.alibaba.cloud.sentinel;
import
java.util.Optional
;
import
com.alibaba.cloud.sentinel.timeloit.CustomBlockExceptionHandler
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.SentinelWebInterceptor
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.DefaultBlockExceptionHandler
;
...
...
@@ -108,8 +109,11 @@ public class SentinelWebAutoConfiguration implements WebMvcConfigurer {
e
)
->
response
.
sendRedirect
(
properties
.
getBlockPage
())));
}
else
{
// sentinelWebMvcConfig
// .setBlockExceptionHandler(new DefaultBlockExceptionHandler());
// for loitTime custom sentinel exception by chenshiying
sentinelWebMvcConfig
.
setBlockExceptionHandler
(
new
Default
BlockExceptionHandler
());
.
setBlockExceptionHandler
(
new
Custom
BlockExceptionHandler
());
}
}
...
...
spring-cloud-timeloit-starters/spring-cloud-starter-timeloit-sentinel/src/main/java/com/alibaba/cloud/sentinel/timeloit/CustomBlockExceptionHandler.java
0 → 100644
浏览文件 @
4c590ec1
package
com
.
alibaba
.
cloud
.
sentinel
.
timeloit
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler
;
import
com.alibaba.csp.sentinel.slots.block.BlockException
;
import
org.springframework.http.HttpStatus
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.PrintWriter
;
public
class
CustomBlockExceptionHandler
implements
BlockExceptionHandler
{
@Override
public
void
handle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
BlockException
e
)
throws
Exception
{
response
.
setStatus
(
HttpStatus
.
OK
.
value
());
response
.
setContentType
(
"application/json;charset=UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
out
.
print
(
"{\"success\":false,\"code\":\"444\",\"msg\":\"系统繁忙请稍后再试\"}"
);
out
.
flush
();
out
.
close
();
}
}
spring-cloud-timeloit-starters/spring-cloud-starter-timeloit-sentinel/src/main/java/com/alibaba/cloud/sentinel/timeloit/README.md
0 → 100644
浏览文件 @
4c590ec1
# 时代凌宇sentinel 自定义异常类
SentinelWebAutoConfiguration.sentinelWebMvcConfig
```
$xslt
// for loitTime custom sentinel exception by chenshiying
sentinelWebMvcConfig
.setBlockExceptionHandler(new CustomBlockExceptionHandler());
```
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论