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. 406 Not Acceptable
  4. Date: Sat, 17 Aug 2013 11:01:07 GMT
  5. Server: Apache-Coyote/1.1
  6. Content-Length: 1067
  7. Content-Type: text/html;charset=utf-8
  8. <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问题解决。

原文地址:https://www.cnblogs.com/dauber/p/9265961.html

时间: 2024-08-01 19:54:42

SpringMVC异常报406 (Not Acceptable)的解决办法的相关文章

Spring MVC 以.html为后缀名访问获取数据,报406 Not Acceptable错误。

如题,最近以spring mvc作为后台框架,前端异步获取数据时(.html为后缀名的访问方式),报406 Not Acceptable错误.当初都不知道啥原因,前后台都没报错就是返回不了数据,于是查了下http 406响应码:406 (SC_NOT_ACCEPTABLE)表示请求资源的MIME类型与客户端中Accept头信息中指定的类型不一致.下面请看出错的操作流程及代码: 1.先配置spring mvc 核心servlet (DispatcherServlet) 至web.xml中,其中配置

在CentOS中安装32位或64位MySql报错error: Failed dependencies解决办法

在CentOS中安装MySql报错error: Failed dependencies解决办法 安装64位MySql报错内容如下:error: Failed dependencies:        libaio.so.1()(64bit) is needed by MySQL-server-5.6.19-1.el6.x86_64    libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.19-1.el6.x86_64    

MVC3在IIS7.5发布(部署)报403.14错误的解决办法

原文链接:http://solin.cn.blog.163.com/blog/static/536402372013410115631805/ 错误现象: 报403.14 forbidden错误 web服务器被配置为不列出此目录的内容. 解决办法: 检查站点的处理程序映射,看是否存在下列映射: ExtensionlessUrlHandler-Integrated-4.0 ExtensionlessUrlHandler-ISAPI-4.0_32bit ExtensionlessUrlHandler

VMware安装报VT-x未开启的解决办法

场景说明:用虚拟机安装64位CentOS 6.5,然后出错,如下: Thishost supports Intel VT-x, but Intel VT-x is disabled. IntelVT-x might be disabled if it has been disabled in the BIOS/firmware settings orthe host has not been power-cycled since changing this setting. (1)Verify 

springmvc @ResponseBody返回json 报406 not acceptable

今天在做springmvc的@ResponseBody返回json的例子时,碰到了这样一个问题"406 (Not Acceptable)",百度之后发现在缺了一个依赖包jackson-databind. 1.spring-mvc.xml配置文件 2.pom.xml文件 [email protected]代码

关于MYSQL:外键删除后,查询表发现外键依旧存在,再删一次会报错:原因及相关解决办法

1.创建表test6:外键名为test3_fk mysql> create table test6( -> id int, -> test_name varchar(32), -> constraint test3_fk foreign key(test_name) references student(name) -> ); Query OK, 0 rows affected (0.40 sec) mysql> desc test6; +-----------+---

【Android】常见异常 —— android.view.WindowLeaked 分析以及解决办法

问题虽小,不过不知道还是比较麻烦的.异常信息: 10-22 10:19:38.651 12723-12723/cn.com.zte.uc E/WindowManager﹕ android.view.WindowLeaked: Activity cn.com.zte.uc.activites.shipTicket.OrderWrite1 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{423fee70

Error parsing XML: not well-formed (invalid token) 报错+R文件消失解决办法

xml报错: 这个xml文件上右键source ->format 注意:res下的文件名不能大写 R文件消失: 在解决了其他问题的情况下(或者其他问题还没解决先注释掉) 手动删除gen project clean后重新build 版权声明:本文为博主原创文章,未经博主允许不得转载.

eclipse下执行wordcount报错 java.lang.ClassNotFoundException 解决办法

eclipse下执行wordcount报错 java.lang.ClassNotFoundException 17/08/29 07:52:54 INFO Configuration.deprecation: fs.default.name is deprecated. Instead, use fs.defaultFS 17/08/29 07:52:54 WARN util.NativeCodeLoader: Unable to load native-hadoop library for y