170616、解决 java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList

时间:2022-03-12 04:34:42

报错截图:

170616、解决 java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList

原因:搭建项目的时候,springmvc默认是没有对象转换成json的转换器的,需要手动添加jackson依赖。

解决步骤:

1、添加jackson依赖到pom.xml

        <!-- jaskson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.4</version>
</dependency>

2、在springmvc.xml增加

<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>

然后问题解决

170616、解决 java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList