gpt4 book ai didi

java - SpringMVC错误: The resource identified by this request is only capable of generating responses

转载 作者:行者123 更新时间:2023-12-02 13:24:17 25 4
gpt4 key购买 nike

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

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

Spring 在以下错误消息中响应 406 状态代码:

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

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

<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 定义如下:

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

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

}

有什么想法我做错了什么吗?

最佳答案

看起来问题是我没有添加所有必要的依赖项,在本例中是jackson-mapper-asl。我认为只添加 jackson-core-asl 就足够了。

关于java - SpringMVC错误: The resource identified by this request is only capable of generating responses,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9237389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com