Spring MVC REST Handing Bad Url (404) by returning JSON

前端 未结 4 818
醉梦人生
醉梦人生 2021-01-30 23:56

I am developing a REST service using SpringMVC, where I have @RequestMapping at class and method level.

This application is currently configured to return error-page js

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-31 00:34

    If you're using spring 3.2 or later you can use a controller advice (@ControllerAdvice) to deal with, amongst other things, mapping errors (404's). You can find documentation here. Take a look at section 17.11. You can use this, for example, to provide more detailed logging on why your request bindings aren't being matched for specific urls, or to simply return a more specific response than a generic 404.

提交回复
热议问题