Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 Exception not handled in Spring ControllerAdvice

Tags:

I have a simple Spring MVC application in which I want to handle all the unmapped urls using @ControllerAdvice. Here is the controller:

@ControllerAdvice
public class ExceptionHandlerController {
    @ResponseStatus(HttpStatus.NOT_FOUND)
    @ExceptionHandler(NoHandlerFoundException.class)
    public String handle404() {
        return "exceptions/404page";
    }
}

Still, every time get Whitelabel Error Page.

I tried using RuntimeException.class, HttpStatus.BAD_REQUEST and extending the class with NoHandlerFoundException but no use.

Any suggestions?