springboot中的406(Not Acceptable)錯誤


今天遇到一個很奇怪的問題,我用springboot開發時,用ajax請求服務想返回json數據,頁面總是報406錯誤,這個錯誤使我郁悶了很久,原來我的后台服務是這么寫的

看到沒value的后面有個.htm,我猜springboot框架會默認以為要返回html頁面,所以一直報406(Not Acceptable)

1.后來我把value里面的.htm去掉了

然后什么問題都沒有了。

2.還有另外的一種解決方式是(這個配置是我同事找到的)

這個解決辦法是在springmvc.xml文件里增加配置

<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false" />
</bean>
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
<!-- 消息轉換器 -->
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes" value="text/html;charset=UTF-8"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM