最近閒來無事,想本身搭建一套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錯誤,就細細分析了下,然後解決了該問題,先拿來備份和分享!java
1.jdk 1.7spring
2.maven 3.3.9sql
3.spring 4.2.6.RELEASEjson
4.springmvc 4.2.6.RELEASEmybatis
5.mybatis 3.2.8mvc
1.緣由:這是由於springmvc默認是沒有對象轉換成json的轉換器的,須要手動添加jackson依賴。app
2.解決步驟:框架
手動添加jackson依賴到pom.xml文件中maven
<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>
若是仍是沒有解決,則進行如下步驟spa
在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>
這樣咱們就完美解決了該問題。
咱們在本身搭建框架的過程當中,必定要學會本身多思考,遇到問題多去翻翻源碼,這樣對咱們解決問題頗有幫助。