Spring MVC错误:此请求标识的资源只能生成响应 [英] Spring MVC error: The resource identified by this request is only capable of generating responses

查看:137
本文介绍了Spring MVC错误:此请求标识的资源只能生成响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在浏览器中调用此URL时:

When I invoke this URL in the browser:

http://localhost:8080/app/foo.json

Spring在此错误消息中回复406状态代码:

Spring responds with 406 Status code in this error message:


此请求标识的资源只能根据请求accept标题()生成具有不可接受特征的响应。

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().

但是我已经定义了我的内容协商视图解析器,如下所示:

However I have defined my content negotiating view resolver like this:

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="favorPathExtension" value="true" />
    <property name="ignoreAcceptHeader" value="true" />

    <property name="mediaTypes">
        <map>
            <entry key="json" value="application/json"/>
            <entry key="html" value="text/html"/>
        </map>
    </property>
</bean>

我的控制器定义如下:

@Controller
@RequestMapping(value = "/foo")
public class ToowootController {

    @RequestMapping(method = GET)
    @ResponseBody
    public FooDTO index() {
        // return fooDTO
    }

}

任何想法我做错了什么?

Any ideas what am I doing wrong?

推荐答案

看起来问题是我没有添加所有必要的依赖项,在这种情况下 jackson-mapper-asl 。我以为只添加 jackson-core-asl 就够了。

Looks like the problem was that I had not added all the necessary dependencies, in this case jackson-mapper-asl. I thought only adding jackson-core-asl would be enough.

这篇关于Spring MVC错误:此请求标识的资源只能生成响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆