javascript
SpringMVC 生成json报 HTTP Status 406.错误的解决方法
這個問題害了我弄了幾天才弄好,后來開了http://www.tuicool.com/articles/FJnmAvY
這篇文章才算把問題解決了。
首先將spring的bean文件頭文件改一下
改成
<?xml version="1.0" encoding="UTF-8"?> ?
? ? <beans xmlns="http://www.springframework.org/schema/beans" ?
? ? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" ?
? ? xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" ?
? ? xmlns:mvc="http://www.springframework.org/schema/mvc" ?
? ? ??
? ? xsi:schemaLocation="http://www.springframework.org/schema/beans ?
? ? ? http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ?
? ? ? http://www.springframework.org/schema/context ?
? ? ? http://www.springframework.org/schema/context/spring-context-3.0.xsd ?
? ? ? http://www.springframework.org/schema/aop ?
? ? ? http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ?
? ? ? http://www.springframework.org/schema/tx ??
? ? ? http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ?
? ? ?http://www.springframework.org/schema/mvc ??
? ? ?http://www.springframework.org/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
這三個包就可以了
轉載于:https://blog.51cto.com/shenymce/1641381
總結
以上是生活随笔為你收集整理的SpringMVC 生成json报 HTTP Status 406.错误的解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: HNOI2015 实验比较
- 下一篇: 箱体行业最薄!TCL零嵌系列冰箱T9发布
