SpringMVC異常報406 (Not Acceptable)的解決辦法


使用SpsringMVC,使用restEasy調試,controller請求設置如下: 
Java代碼   收藏代碼
  1. @RequestMapping(value="/list",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)  
  2. @ResponseBody  
  3. public List<EditTimeout> list(){  
  4.      List<EditTimeout> list = editImpl.selectAll();  
  5.     return list;  
  6. }  


請求,debug跟蹤list是返回值沒有問題,但是前台頁面報如下錯誤: 
Java代碼   收藏代碼
  1. Response Status: 406 (Not Acceptable)  


Response RAW返回值如下,(前半部分) 
Xml代碼   收藏代碼
  1. HTTP GET http://127.0.0.1:8080/onlineLibrary/rest/system/editTimeout/list  
  2. Host: 127.0.0.1:8080  
  3.   
  4.   
  5. 406 Not Acceptable  
  6. Date: Sat, 17 Aug 2013 11:01:07 GMT  
  7. Server: Apache-Coyote/1.1  
  8. Content-Length: 1067  
  9. Content-Type: text/html;charset=utf-8  
  10. <html><head><title>Apache Tomcat/7.0.34 - Error report</title><style>  


后台提示錯誤: 
Java代碼   收藏代碼
  1. 2013-08-17 19:01:03,116 DEBUG org.springframework.web.servlet.DispatcherServlet -Last-Modified value for [/onlineLibrary/rest/system/editTimeout/list] is: -1  
  2. 2013-08-17 19:01:07,606 DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation  
  3. 2013-08-17 19:01:07,680 DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation  
  4. 2013-08-17 19:01:07,681 DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation  




引起的原因: 
   由於設置了@ResponseBody,要把對象轉換成json格式,缺少轉換依賴的jar包,故此錯。 
解決辦法: 
   加入依賴的jar,jackson-core-asl-1.9.12.jar,jackson-mapper-asl-1.9.12.jar問題解決。


免責聲明!

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



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