全局异常类注册bean
This commit is contained in:
parent
6dcde8295a
commit
c420ff3bea
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user