diff --git a/zxwl-common/zxwl-common-satoken/src/main/java/org/zxwl/common/satoken/config/SaTokenConfig.java b/zxwl-common/zxwl-common-satoken/src/main/java/org/zxwl/common/satoken/config/SaTokenConfig.java index de3380f..59a454f 100644 --- a/zxwl-common/zxwl-common-satoken/src/main/java/org/zxwl/common/satoken/config/SaTokenConfig.java +++ b/zxwl-common/zxwl-common-satoken/src/main/java/org/zxwl/common/satoken/config/SaTokenConfig.java @@ -7,9 +7,11 @@ import cn.dev33.satoken.stp.StpUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.zxwl.common.satoken.handler.SaTokenExceptionHandler; @Slf4j @Configuration @@ -32,4 +34,12 @@ public class SaTokenConfig implements WebMvcConfigurer { SaRouter.match("/**").check(StpUtil::checkLogin); })).addPathPatterns("/**").excludePathPatterns(securityProperties.getExcludes()); } + + /** + * 全局异常处理器 + */ + @Bean + public SaTokenExceptionHandler saTokenExceptionHandler() { + return new SaTokenExceptionHandler(); + } } diff --git a/zxwl-common/zxwl-common-web/src/main/java/org/zxwl/common/web/config/CorsConfig.java b/zxwl-common/zxwl-common-web/src/main/java/org/zxwl/common/web/config/CorsConfig.java index 21d8be4..02cd54a 100644 --- a/zxwl-common/zxwl-common-web/src/main/java/org/zxwl/common/web/config/CorsConfig.java +++ b/zxwl-common/zxwl-common-web/src/main/java/org/zxwl/common/web/config/CorsConfig.java @@ -1,8 +1,10 @@ package org.zxwl.common.web.config; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.zxwl.common.web.handler.GlobalExceptionHandler; @Configuration public class CorsConfig implements WebMvcConfigurer { @@ -16,4 +18,12 @@ public class CorsConfig implements WebMvcConfigurer { .maxAge(3600) .allowedHeaders("*"); } + + /** + * 全局异常处理器 + */ + @Bean + public GlobalExceptionHandler globalExceptionHandler() { + return new GlobalExceptionHandler(); + } } diff --git a/zxwl-common/zxwl-common-core/src/main/java/org/zxwl/common/core/exception/GlobalExceptionHandler.java b/zxwl-common/zxwl-common-web/src/main/java/org/zxwl/common/web/handler/GlobalExceptionHandler.java similarity index 97% rename from zxwl-common/zxwl-common-core/src/main/java/org/zxwl/common/core/exception/GlobalExceptionHandler.java rename to zxwl-common/zxwl-common-web/src/main/java/org/zxwl/common/web/handler/GlobalExceptionHandler.java index ffd46bc..d7efeee 100644 --- a/zxwl-common/zxwl-common-core/src/main/java/org/zxwl/common/core/exception/GlobalExceptionHandler.java +++ b/zxwl-common/zxwl-common-web/src/main/java/org/zxwl/common/web/handler/GlobalExceptionHandler.java @@ -1,4 +1,4 @@ -package org.zxwl.common.core.exception; +package org.zxwl.common.web.handler; import cn.hutool.http.HttpStatus; import jakarta.servlet.http.HttpServletRequest; @@ -9,6 +9,7 @@ import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.zxwl.common.core.domain.Result; +import org.zxwl.common.core.exception.BusinessException; import java.util.Objects;