Commit 08d39d4593c9fd21eccf75e11e2c09eb3f36af00
1 parent
1f327ef8
默认禁用 resilience4j 依赖,保证启动速度
Showing
3 changed files
with
9 additions
and
14 deletions
yudao-framework/yudao-spring-boot-starter-protection/pom.xml
yudao-framework/yudao-spring-boot-starter-web/pom.xml
| ... | ... | @@ -55,13 +55,6 @@ |
| 55 | 55 | <version>${revision}</version> |
| 56 | 56 | </dependency> |
| 57 | 57 | |
| 58 | - <!-- 服务保障相关 --> | |
| 59 | - <dependency> | |
| 60 | - <groupId>io.github.resilience4j</groupId> | |
| 61 | - <artifactId>resilience4j-ratelimiter</artifactId> | |
| 62 | - <scope>provided</scope> <!-- 设置为 provided,主要是 GlobalExceptionHandler 使用 --> | |
| 63 | - </dependency> | |
| 64 | - | |
| 65 | 58 | <!-- xss --> |
| 66 | 59 | <dependency> |
| 67 | 60 | <groupId>org.jsoup</groupId> | ... | ... |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
| ... | ... | @@ -11,7 +11,6 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 11 | 11 | import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; |
| 12 | 12 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 13 | 13 | import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; |
| 14 | -import io.github.resilience4j.ratelimiter.RequestNotPermitted; | |
| 15 | 14 | import lombok.AllArgsConstructor; |
| 16 | 15 | import lombok.extern.slf4j.Slf4j; |
| 17 | 16 | import org.apache.commons.lang3.exception.ExceptionUtils; |
| ... | ... | @@ -33,6 +32,7 @@ import javax.validation.ConstraintViolationException; |
| 33 | 32 | import javax.validation.ValidationException; |
| 34 | 33 | import java.time.LocalDateTime; |
| 35 | 34 | import java.util.Map; |
| 35 | +import java.util.Objects; | |
| 36 | 36 | |
| 37 | 37 | import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.*; |
| 38 | 38 | |
| ... | ... | @@ -83,9 +83,6 @@ public class GlobalExceptionHandler { |
| 83 | 83 | if (ex instanceof HttpRequestMethodNotSupportedException) { |
| 84 | 84 | return httpRequestMethodNotSupportedExceptionHandler((HttpRequestMethodNotSupportedException) ex); |
| 85 | 85 | } |
| 86 | - if (ex instanceof RequestNotPermitted) { | |
| 87 | - return requestNotPermittedExceptionHandler(request, (RequestNotPermitted) ex); | |
| 88 | - } | |
| 89 | 86 | if (ex instanceof ServiceException) { |
| 90 | 87 | return serviceExceptionHandler((ServiceException) ex); |
| 91 | 88 | } |
| ... | ... | @@ -186,8 +183,7 @@ public class GlobalExceptionHandler { |
| 186 | 183 | /** |
| 187 | 184 | * 处理 Resilience4j 限流抛出的异常 |
| 188 | 185 | */ |
| 189 | - @ExceptionHandler(value = RequestNotPermitted.class) | |
| 190 | - public CommonResult<?> requestNotPermittedExceptionHandler(HttpServletRequest req, RequestNotPermitted ex) { | |
| 186 | + public CommonResult<?> requestNotPermittedExceptionHandler(HttpServletRequest req, Throwable ex) { | |
| 191 | 187 | log.warn("[requestNotPermittedExceptionHandler][url({}) 访问过于频繁]", req.getRequestURL(), ex); |
| 192 | 188 | return CommonResult.error(TOO_MANY_REQUESTS); |
| 193 | 189 | } |
| ... | ... | @@ -226,7 +222,12 @@ public class GlobalExceptionHandler { |
| 226 | 222 | return tableNotExistsResult; |
| 227 | 223 | } |
| 228 | 224 | |
| 229 | - // 情况二:处理异常 | |
| 225 | + // 情况二:部分特殊的库的处理 | |
| 226 | + if (Objects.equals("io.github.resilience4j.ratelimiter.RequestNotPermitted", ex.getClass().getName())) { | |
| 227 | + return requestNotPermittedExceptionHandler(req, ex); | |
| 228 | + } | |
| 229 | + | |
| 230 | + // 情况三:处理异常 | |
| 230 | 231 | log.error("[defaultExceptionHandler]", ex); |
| 231 | 232 | // 插入异常日志 |
| 232 | 233 | this.createExceptionLog(req, ex); | ... | ... |