json转换错误:No converter found for return value of type
来源:互联网 发布:网络攻防入门 编辑:程序博客网 时间:2024/06/10 01:36
No converter found for return value of type: class java.util.HashMap
最近在搭建一个spring+springMVC+Mybatis项目,其中spring是4.2.0版本,但是在ajax与后台交互的时候,前台的ajax一直接收不到controller返回来的数据:
- 代码如下
前台代码(ajax代码块):
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
后台controller方法:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
问题:
运行后,ajax可以访问controller方法,但是返回的json数据后,ajax的success接收不到,提示的错误是:
Java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.HashMap
从错误信息的原因来看,是后台返回的json数据与ajax的dataType:”json” 不匹配,但是@responseBody注解会自动将返回数据封装成json格式,猜想是配置的问题,还有json包版本冲突
于是重新配置了一下applicationContext.xml里面的配置:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
重新导2.7版本的jackson相关包:
jackson-databind-2.7.4.jar
jackson-annotations-2.7.4.jar
jackson-core-2.7.4.jar
以上jar包下载地址(拷贝下面URL在新页面打开,不然下载不了):
http://cdn.sojson.com/file/16-05-03-20-51-11/json-jar.zip
如果是Maven项目,则依赖如下:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
最后,困扰我几天的问题解决了。应该是json的包版本问题,如果你也遇到问题。可以先排除配置和包问题这两方面。
最后,感谢部门的龙哥帮忙,找到了问题的根本。
也感谢这个相关帖子提供相关配置说明:http://www.sojson.com/blog/133.html
- json转换错误:No converter found for return value of type
- json转换错误:No converter found for return value of type
- No converter found for return value of type解决方法
- SpringMVC 返回json数据报错IllegalArgumentException: No converter found for return value of type:xxx
- springboot错误 java.lang.IllegalArgumentException:No converter found for return value of type
- springMVC返回json格式数据报错:No converter found for return value of type: class java.util.HashMap
- springMVC返回json格式数据报错:No converter found for return value of type: class java.util.HashMap
- java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.Has
- java.lang.IllegalArgumentException: No converter found for return value of type: class
- 记录下报错:java.lang.IllegalArgumentException: No converter found for return value of type: class
- HttpMessageConverter配置javaconfig(未配置异常:No converter found for return value of type)
- springboot访问方法时出错:Spring Boot Application: No converter found for return value of type
- springmvc框架报错java.lang.IllegalArgumentException: No converter found for return value of type: class
- java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.Has
- Spring MVC No converter found for return value of type 解决方法
- java.lang.IllegalArgumentException: No converter found for return value of type
- Spring MVC No converter found for return value of type 解决方法
- java.lang.IllegalArgumentException: No converter found for return value of type:class 解决方案
- Swift中performSelector返回值的用法
- P1151 子数整数
- IntelliJIdea 快捷键
- 【高效学习秘诀2】——Know Can Do
- 盒子升级apk
- json转换错误:No converter found for return value of type
- 简单的动态网页设计及开发(关联数据库)
- VScode配置C++编译环境
- OpenCV学习笔记5-滑动条的使用
- SSM框架搭建
- 【循环数组最大子段和】51nod 1050 循环数组最大子段和
- stanfordNLP中文java+maven构建测试
- ubuntu jdk安装
- 公司无法上网,只能上QQ