spring mvc HTTP Status 406 错误

错误信息:

spring mvc HTTP Status 406 错误_第1张图片
spring mvc HTTP Status 406 错误_第2张图片

查看spring-mvc的配置文件:

spring mvc HTTP Status 406 错误_第3张图片

再次查看错误信息:

description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().其字面意思:产生的格式跟能接受的格式不符。查询多种资料都说什么没有添加json支持的包。于是查看依赖:

spring mvc HTTP Status 406 错误_第4张图片

存在的。

接着查找:

发现Spring默认ContentNegotiationManager使用org.springframework.web.accept.ServletPathExtensionContentNegotiationStrategy解析可接受的media type,这貌似是Spring 3哪个版本以后开始的特性解决方案:在spring-mvc.xml文件中添加:

spring mvc HTTP Status 406 错误_第5张图片


​说明:如果配置文件中使用了。以上两个bean需要定义在其之前呢。

凯哥Java

你可能感兴趣的:(spring mvc HTTP Status 406 错误)