ssm框架前后端连接出现问题——java.lang.IllegalArgumentException: No converter found for return value of type: cla

本文详细介绍了在使用SpringMVC框架时遇到的java.lang.IllegalArgumentException异常,该异常源于对象到JSON转换的问题。文章提供了两种解决方案:一是添加Jackson依赖以实现对象与JSON之间的转换;二是通过在SpringMVC配置文件中指定消息转换器来解决转换问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:java.lang.IllegalArgumentException: No converter found for return value of type: class sun.ssm.commo

转载出处:https://www.cnblogs.com/hafiz/p/5812873.html

搭建版本:

        <spring.version>4.3.3.RELEASE</spring.version>
        <mybatis.version>3.4.1</mybatis.version>
        <slf4j.version>1.7.7</slf4j.version>
        <log4j.version>1.2.17</log4j.version>
        <mysql.version>5.1.30</mysql.version>

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>

我利用方法1解决了我的问题 


 

如果还是没有解决,则进行以下步骤

  在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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值