1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > SpringMVC 生成json报 HTTP Status 406.错误的解决方法

SpringMVC 生成json报 HTTP Status 406.错误的解决方法

时间:2022-12-06 08:06:21

相关推荐

SpringMVC 生成json报 HTTP Status 406.错误的解决方法

这个问题害了我弄了几天才弄好,后来开了/articles/FJnmAvY

这篇文章才算把问题解决了。

首先将spring的bean文件头文件改一下

改成

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="/schema/beans"

xmlns:xsi="/2001/XMLSchema-instance" xmlns:context="/schema/context"

xmlns:aop="/schema/aop" xmlns:tx="/schema/tx"

xmlns:mvc="/schema/mvc"

xsi:schemaLocation="/schema/beans

/schema/beans/spring-beans-3.0.xsd

/schema/context

/schema/context/spring-context-3.0.xsd

/schema/aop

/schema/aop/spring-aop-3.0.xsd

/schema/tx

/schema/tx/spring-tx-3.0.xsd

/schema/mvc

/schema/mvc/spring-mvc-3.2.xsd">

也就是把以前spring-mvc-3.0.xsd 升级到 spring-mvc-3.2.xsd,如果已经是spring-mvc-3.2.xsd的就不用改了

然后把<mvc:annotation-driven>修改成如下格式

<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />

<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">

<property name="favorPathExtension" value="false" />

<property name="favorParameter" value="false" />

<property name="ignoreAcceptHeader" value="false" />

<property name="mediaTypes" >

<value>

atom=application/atom+xml

html=text/html

json=application/json

*=*/*

</value>

</property>

</bean>

jackson的包就引用

jackson-core-2.5.2.jar

jackson-annotations-2.5.2.jar

jackson-databind-2.5.2.jar

这三个包就可以了

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。