来自SpringREST控制器的JSON响应

来自SpringREST控制器的JSON响应,spring,rest,spring-mvc,spring-rest,Spring,Rest,Spring Mvc,Spring Rest,我收到HTTP错误代码406,错误描述如下: The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers. 我的目标是在json响应中获取我的POJO类。请查找我的以下配置: @RequestMapping(value="/testjson"

我收到HTTP错误代码406,错误描述如下:

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
我的目标是在json响应中获取我的POJO类。请查找我的以下配置:

@RequestMapping(value="/testjson",produces="application/json")
    public @ResponseBody Employee testjson () {
        System.err.println("testing json");
        Employee testEmp = new Employee("1", "Ankit", "Agarwal");

        return testEmp;
    }
spring-servlet.xml

试试这个

@RequestMapping(value="/testjson",produces="application/json",headers = {"Content-type=application/json"})

我已经添加了spring-servlet.xml,并且可以看到POJO类的json响应。我删除了spring-servlet.xml中的bean ContentNegotiatingViewResolver,还删除了RequestMapping上的products=application/json。我仍然可以在这个url上看到json响应。有人知道从哪里捕获的响应将是json类型的吗?请编辑更多信息。不鼓励只编码并尝试此答案,因为它们不包含可搜索的内容,并且不解释为什么有人应该尝试此答案。我们努力成为知识的资源,我唯一关心的是我在类中删除了products=application/json。我仍然能够得到json响应。我想知道春天的哪个地方会这样。谢谢你的回复。
@RequestMapping(value="/testjson",produces="application/json",headers = {"Content-type=application/json"})