Spring Boot全局异常捕捉
项目中的异常统一处理
package hello; import javax.servlet.http.HttpServletRequest; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; /** * 全局异常捕获 */ @ControllerAdvice public class GlobalDefaultExceptionHandler { @ExceptionHandler(value = Exception.class) public void defaultErrorHandler(HttpServletRequest httpServletRequest, Exception exception) { // 打印异常信息 exception.printStackTrace(); System.out.println("GlobalDefaultExceptionHandler.defaultErrorHandler()"); } }