I want to override html error page for 404 responses as an JSON response. When i use @ControllerAdvice without @EnableWebMvc it is not working.
Normally @utkusonmez answer works fine but not in my case, as I am using swagger. So all I did is add following properties in my application.properties file
spring.mvc.throw-exception-if-no-handler-found=true
spring.mvc.static-path-pattern=/swagger*
Now both NoHandlerFoundException and swagger-ui works fine.