There is a server built on Spring + Hibernate. It is necessary to catch the error 404 when the user knocks on the wrong address (for example, localhost: 8080 / tes instead of test). For this, I wrote GlobalExceptionHandlerController.class . It perfectly catches all errors except 404. What is the problem?
@ControllerAdvice public class GlobalExceptionHandlerController { @ResponseStatus(value = HttpStatus.NOT_FOUND) @ExceptionHandler(value = NullPointerException.class) @ResponseBody public String handleNullPointerException(Exception e) { System.out.println("A null pointer exception ocurred " + e); return "nullpointerExceptionPage"; } @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(value = Exception.class) @ResponseBody public String handleAllException(Exception e) { System.out.println("A unknow Exception Ocurred: " + e); return "unknowExceptionPage"; } @ExceptionHandler(NoHandlerFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) @ResponseBody public String handleResourceNotFoundException() { return "notFoundJSPPage"; } }