I use @ExceptionHandler to handle exceptions thrown by my web app, in my case my app returns JSON response with HTTP status for error responses to the client.
However, I am trying to figure out how to handle error 404 to return a similar JSON response like with the one handled by @ExceptionHandler
Update:
I mean, when a URL that does not exist is accessed
Simplest way to find out is use the following:
If the URL is within the scope of DispatcherServlet then any 404 caused by mistyping or anything else will be caught by this method but if the URL typed is beyond the URL mapping of the DispatcherServlet then you have to either use:
or