Custom exception handler for NoHandlerFoundException is not working without @EnableWebMvc

前端 未结 3 1270
猫巷女王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:54

    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.

提交回复
热议问题