springMVC請求出現406錯誤
阿新 • • 發佈:2019-01-31
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">1,專案一直用的spring 3.2.3版本+jackson 1.9.11版本。請求一直沒有問題</span>
2,今天把spring版本升到4.1以上的版本就出現了問題
報錯資訊:
<pre name="code" class="java"> Resolving exception from handler [public java.lang.Object com.wulongyuan.controller.DemoController.test()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation Resolving exception from handler [public java.lang.Object com.wulongyuan.controller.DemoController.test()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation Resolving exception from handler [public java.lang.Object com.wulongyuan.controller.DemoController.test()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation Resolving exception from handler [public java.lang.Object com.wulongyuan.controller.DemoController.test()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation Resolving exception from handler [public java.lang.Object com.wulongyuan.controller.DemoController.test()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation DE
</pre><p></p><pre>
3,首先我的配置檔案是沒有問題的 因為之前都能用,只是把版本改了而已
讓後就去看Spring官方文件 發現sping4.已經 對jackson1.9不支援了,為了測試,我將我spring的版本改回3.2+的版本。發現正常通過。因此又將版本改回,然後把jaskson的版本改為2.5
<jackson.version>2.5.0</jackson.version> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency>