默认禁用 resilience4j 依赖,保证启动速度

This commit is contained in:
YunaiV 2023-09-16 12:01:56 +08:00
parent 09c018fa13
commit 2769ee3635
3 changed files with 15 additions and 20 deletions

View File

@ -31,6 +31,7 @@
<dependency> <dependency>
<groupId>io.github.resilience4j</groupId> <groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId> <artifactId>resilience4j-spring-boot2</artifactId>
<optional>true</optional>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -67,13 +67,6 @@
<artifactId>yudao-module-infra-api</artifactId> <!-- 需要使用它,进行操作日志的记录 --> <artifactId>yudao-module-infra-api</artifactId> <!-- 需要使用它,进行操作日志的记录 -->
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<!-- 服务保障相关 -->
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-ratelimiter</artifactId>
<scope>provided</scope> <!-- 设置为 provided主要是 GlobalExceptionHandler 使用 -->
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -32,6 +32,7 @@ import javax.validation.ConstraintViolationException;
import javax.validation.ValidationException; import javax.validation.ValidationException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.*; import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.*;
@ -82,9 +83,6 @@ public class GlobalExceptionHandler {
if (ex instanceof HttpRequestMethodNotSupportedException) { if (ex instanceof HttpRequestMethodNotSupportedException) {
return httpRequestMethodNotSupportedExceptionHandler((HttpRequestMethodNotSupportedException) ex); return httpRequestMethodNotSupportedExceptionHandler((HttpRequestMethodNotSupportedException) ex);
} }
// if (ex instanceof RequestNotPermitted) {
// return requestNotPermittedExceptionHandler(request, (RequestNotPermitted) ex);
// }
if (ex instanceof ServiceException) { if (ex instanceof ServiceException) {
return serviceExceptionHandler((ServiceException) ex); return serviceExceptionHandler((ServiceException) ex);
} }
@ -182,15 +180,13 @@ public class GlobalExceptionHandler {
return CommonResult.error(METHOD_NOT_ALLOWED.getCode(), String.format("请求方法不正确:%s", ex.getMessage())); return CommonResult.error(METHOD_NOT_ALLOWED.getCode(), String.format("请求方法不正确:%s", ex.getMessage()));
} }
// TODO 芋艿暂时去掉 /**
// /** * 处理 Resilience4j 限流抛出的异常
// * 处理 Resilience4j 限流抛出的异常 */
// */ public CommonResult<?> requestNotPermittedExceptionHandler(HttpServletRequest req, Throwable ex) {
// @ExceptionHandler(value = RequestNotPermitted.class) log.warn("[requestNotPermittedExceptionHandler][url({}) 访问过于频繁]", req.getRequestURL(), ex);
// public CommonResult<?> requestNotPermittedExceptionHandler(HttpServletRequest req, RequestNotPermitted ex) { return CommonResult.error(TOO_MANY_REQUESTS);
// log.warn("[requestNotPermittedExceptionHandler][url({}) 访问过于频繁]", req.getRequestURL(), ex); }
// return CommonResult.error(TOO_MANY_REQUESTS);
// }
/** /**
* 处理 Spring Security 权限不足的异常 * 处理 Spring Security 权限不足的异常
@ -226,7 +222,12 @@ public class GlobalExceptionHandler {
return tableNotExistsResult; return tableNotExistsResult;
} }
// 情况二处理异常 // 情况二部分特殊的库的处理
if (Objects.equals("io.github.resilience4j.ratelimiter.RequestNotPermitted", ex.getClass().getName())) {
return requestNotPermittedExceptionHandler(req, ex);
}
// 情况三处理异常
log.error("[defaultExceptionHandler]", ex); log.error("[defaultExceptionHandler]", ex);
// 插入异常日志 // 插入异常日志
this.createExceptionLog(req, ex); this.createExceptionLog(req, ex);