[Java Spring] Global exception handler for application with @ControllerAdvice

Create file:

// this apply to all the controllers
@ControllerAdvice
public class ApplicationExceptionHandler {
    
    @ExceptionHandler(ApplicationException.class)
    public String handleException() {
        System.out.println("in global exception handler");
        return "error";
    }
}

 

posted @ 2021-01-13 19:36  Zhentiw  阅读(70)  评论(0编辑  收藏  举报