Spring 3.x JSON status 406 “characteristics not acceptable according to the request ”accept“ headers ()”

后端 未结 14 1457
太阳男子
太阳男子 2020-12-13 01:50

Upon trying to get my response in JSON using Spring 3.x, I get the 406 error \"The resource identified by this request is only capable

14条回答
  •  遥遥无期
    2020-12-13 02:27

    I think you need to add a produces="application/json" to your @RequestMapping (haven't looked at spring mvc in a while so i'm not 100% positive) ...

    http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html

    16.3.2.6 Producible Media Types

    You can narrow the primary mapping by specifying a list of producible media types. The request will be matched only if the Accept request header matches one of these values. Furthermore, use of the produces condition ensures the actual content type used to generate the response respects the media types specified in the produces condition. For example:

    @Controller
    @RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, produces="application/json")
    @ResponseBody
    public Pet getPet(@PathVariable String petId, Model model) {    
        // implementation omitted
    }
    

提交回复
热议问题