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()");
    }
}

 

posted @ 2018-12-25 10:51  FreeFall  阅读(298)  评论(0编辑  收藏  举报