I want to override html error page for 404 responses as an JSON response. When i use @ControllerAdvice
without @EnableWebMvc
it is not working.
I easily resolved problem by adding one of configurations in application.yml.
spring.mvc.throw-exception-if-no-handler-found=true
spring.resources.add-mappings=false
or
spring.mvc.throw-exception-if-no-handler-found=true
spring.mvc.static-path-pattern: /static
If you don't restrict Spring and no handler matches with your request, then spring tries to look for static content.