最近闲来无事,想自己搭建一套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.lang.IllegalArgumentE:No converter found for return value of type: class java.util.ArrayList

 

    手动添加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>

 

相关文章:

  • 2022-12-23
  • 2022-03-02
  • 2021-08-31
  • 2021-12-13
  • 2021-11-11
  • 2021-08-19
  • 2022-12-23
  • 2021-10-12
猜你喜欢
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2021-06-13
  • 2021-07-13
  • 2021-03-30
  • 2022-01-19
相关资源
相似解决方案