Class GlobalExceptionHandler

java.lang.Object
com.elitesland.ystdms.sys.exception.GlobalExceptionHandler

@ControllerAdvice public class GlobalExceptionHandler extends Object
全局异常处理器 - Spring Boot 3.5 最佳实践 确保在发生异常时也能清理MDC
  • Constructor Details

    • GlobalExceptionHandler

      public GlobalExceptionHandler()
  • Method Details

    • handleBusinessException

      @ExceptionHandler(BusinessException.class) public org.springframework.http.ResponseEntity<ApiResult<Object>> handleBusinessException(BusinessException e, jakarta.servlet.http.HttpServletRequest request)
      处理业务异常
    • handleValidationException

      @ExceptionHandler(ValidationException.class) public org.springframework.http.ResponseEntity<ApiResult<Object>> handleValidationException(ValidationException e, jakarta.servlet.http.HttpServletRequest request)
      处理验证异常
    • handleResourceNotFoundException

      @ExceptionHandler(ResourceNotFoundException.class) public org.springframework.http.ResponseEntity<ApiResult<Object>> handleResourceNotFoundException(ResourceNotFoundException e, jakarta.servlet.http.HttpServletRequest request)
      处理资源未找到异常
    • handleUnauthorizedException

      @ExceptionHandler(UnauthorizedException.class) public org.springframework.http.ResponseEntity<ApiResult<Object>> handleUnauthorizedException(UnauthorizedException e, jakarta.servlet.http.HttpServletRequest request)
      处理未授权异常
    • handleValidationException

      @ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class) public org.springframework.http.ResponseEntity<ApiResult<Object>> handleValidationException(org.springframework.web.bind.MethodArgumentNotValidException e, jakarta.servlet.http.HttpServletRequest request)
      处理参数验证异常 (MethodArgumentNotValidException)
    • handleBindException

      @ExceptionHandler(org.springframework.validation.BindException.class) public org.springframework.http.ResponseEntity<ApiResult<Object>> handleBindException(org.springframework.validation.BindException e, jakarta.servlet.http.HttpServletRequest request)
      处理绑定异常 (BindException)
    • handleMissingParams

      @ExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException.class) public org.springframework.http.ResponseEntity<ApiResult<Object>> handleMissingParams(org.springframework.web.bind.MissingServletRequestParameterException e, jakarta.servlet.http.HttpServletRequest request)
      处理缺少请求参数异常
    • handleTypeMismatch

      @ExceptionHandler(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException.class) public org.springframework.http.ResponseEntity<ApiResult<Object>> handleTypeMismatch(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException e, jakarta.servlet.http.HttpServletRequest request)
      处理方法参数类型不匹配异常
    • handleMessageNotReadable

      @ExceptionHandler(org.springframework.http.converter.HttpMessageNotReadableException.class) public org.springframework.http.ResponseEntity<ApiResult<Object>> handleMessageNotReadable(org.springframework.http.converter.HttpMessageNotReadableException e, jakarta.servlet.http.HttpServletRequest request)
      处理HTTP消息不可读异常 (如JSON格式错误)
    • handleGenericException

      @ExceptionHandler(java.lang.Exception.class) public org.springframework.http.ResponseEntity<ApiResult<Object>> handleGenericException(Exception e, jakarta.servlet.http.HttpServletRequest request)
      处理所有其他未捕获的异常
    • handleRuntimeException

      @ExceptionHandler(java.lang.RuntimeException.class) public org.springframework.http.ResponseEntity<ApiResult<Object>> handleRuntimeException(RuntimeException e, jakarta.servlet.http.HttpServletRequest request)
      处理运行时异常