[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";
    }
}
原文地址:https://www.cnblogs.com/Answer1215/p/14273999.html