解决springmvc报No converter found for return value of type: class java.util.ArrayList问题
一、背景
最近闲来无事,想自己搭建一套Spring+SpringMVC+Mybatis+Mysql的环境(搭建步骤会在以后博客中给出),结果运行程序时,适用@ResponseBody注解进行返回List<对象>的json数据时出现了:nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList错误,就细细分析了下,而后解决了该问题,先拿来备份和分享!
二、框架搭建环境
1.jdk 1.7
2.maven 3.3.9
3.spring 4.2.6.RELEASE
4.springmvc 4.2.6.RELEASE
5.mybatis 3.2.8
三、错误原因及解决步骤
1.原因:这是因为springmvc默认是没有对象转换成json的转换器的,需要手动添加jackson依赖。
2.解决步骤:
手动添加jackson依赖到pom.xml文件中
<properties>
<jackson.version>2.5.4</jackson.version>
</properties>
<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>
如果还是没有解决,则进行以下步骤
在springmvc配置文件中进行如下配置
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
这样我们就完美解决了该问题。
四、总结
我们在自己搭建框架的过程中,一定要学会自己多思考,遇到问题多去翻翻源码,这样对我们解决问题很有帮助。
解决springmvc报No converter found for return value of type: class java.util.ArrayList问题的更多相关文章
- 解决Spring MVC报No converter found for return value of type:class java.util.ArrayList问题
一.背景 在搭建一套Spring+SpringMVC+Mybatis(SSM)的环境(搭建步骤会在以后博客中给出),结果运行 程序时,适用@ResponseBody注解进行返回List<对象&g ...
- 解决java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList问题
在spring + springmvc + mybatis框架中,我们配置接口对外返回json格式,但是报如下错误: 24-Oct-2017 17:42:23.495 严重 [http-nio-808 ...
- 解决No converter found for return value of type: class java.util.ArrayList
十一月 02, 2018 7:37:44 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() f ...
- 解决java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList的问题
一.背景 最近闲来无事,想自己搭建一套Spring+SpringMVC+Mybatis+Mysql的环境(搭建步骤会在以后博客中给出),结果运行程序时,适用@ResponseBody注解进行返回Lis ...
- SSM报错:No converter found for return value of type: class java.util.ArrayList at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverter
我使用的是SSM框架,是在编写测试RESTFUL接口的时候出现, @RequestMapping(value = "/selectAll", method = RequestMet ...
- 解决java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList这个问题
今天使用SSM框架,用@ResponseBody注解,出现了这个问题 java.lang.IllegalArgumentException: No converter found for return ...
- $.ajax函数调接口,报异常No converter found for return value of type: class java.util.ArrayList
接口正常执行,返回给前端后报服务器500异常,异常详情: org.springframework.http.converter.HttpMessageNotWritableException: No ...
- 【Spring】No converter found for return value of type: class java.util.ArrayList
错误信息: org.springframework.http.converter.HttpMessageNotWritableException: No converter found for ret ...
- Idea中:No converter found for return value of type: class java.util.ArrayList:Json格式转换问题
1.在搞SSM框架的时候,前端发送请求后,显示如下错误. @ResponseBody注解进行返回List<对象>的json数据时出现 nested exception is java.la ...
随机推荐
- 贝赛尔曲线UIBezierPath(后续)
使用CAShapeLayer与UIBezierPath可以实现不在view的drawRect方法中就画出一些想要的图形 . 1:UIBezierPath: UIBezierPath是在 UIKit 中 ...
- iOS-绘图
0 CGContextRef context = UIGraphicsGetCurrentCont ext(); 设置上下文 1 CGContextMoveToPoint 开始画线 2 CGCon ...
- centeros:生产环境搭建
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Helvetica Neue"; color: #e4af0a } p. ...
- CSS中清除浮动的两种方式
在CSS中,父元素中的子元素如果使用了float,会导致父元素塌陷,高度为0. 对于这种情况,常见的解决方式有两种. 一.增加新的div,应用clear:both属性 html: <div cl ...
- Mac OS sierra app is damaged
想升级系统,然后发生如题错误,谷歌之,解决方法如下(希望帮助大家): Step 1. Go to your applications folder. Step 2. Find the installe ...
- 微信学习总结 02 ngrok 部署本机代码,使外网可以访问
一 什么是ngrok ngrok is a reverse proxy that creates a secure tunnel from a public endpoint to a locally ...
- chose.jquery 多选
<select id="language" data-placeholder="选择类别..." class="chosen-select&qu ...
- JS,删除数据时候,多次确认后才删除。
function delfun(){ if(window.confirm("请仔细核对无误,删除本数据后不能恢复.")){ if(window.confirm("请再次确 ...
- iOS组件化思路 <转>
随着应用需求逐步迭代,应用的代码体积将会越来越大,为了更好的管理应用工程,我们开始借助CocoaPods版本管理工具对原有应用工程进行拆分.但是仅仅完成代码拆分还不足以解决业务之间的代码耦合,为了更好 ...
- [从产品角度学EXCEL 00]-为什么要关注EXCEL的本质
前言 Hello 大家好,我是尾巴,从今天开始,在这里连载<从产品角度学EXCEL>的系列文章.本文不接受无授权转载,如需转载,请先联系我,非常感谢. 与世面上的大部分EXCEL教程不同的 ...