Custom exception handler for NoHandlerFoundException is not working without @EnableWebMvc

前端 未结 3 1237
猫巷女王i
猫巷女王i 2021-01-13 01:00

I want to override html error page for 404 responses as an JSON response. When i use @ControllerAdvice without @EnableWebMvc it is not working.

3条回答
  •  北海茫月
    2021-01-13 01:57

    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.

提交回复
热议问题