SpringBoot项目Controller层返回对象提示异常:No converter found for return value of type【解决办法】

本文详细解析了在SpringMVC中遇到的JSON转换异常问题,提供了具体的解决方案,包括引入必要的Jackson库依赖以及调整SpringBoot-web依赖配置,确保应用程序能够正确处理JSON数据。

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

完整的异常信息如下:

Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class java.util.LinkedHashMap

出现以上错误,原因在于,缺少了springmvc进行json转换需要的jar包,引入对应jar依赖:

<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-core</artifactId>
  <version>2.9.6</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-annotations</artifactId>
  <version>2.9.6</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.9.6</version>
</dependency>

另外在pom文件中如果引入springboot-web依赖排除掉了springboot-web自带的json也会导致上面的异常信息:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
  <exclusions>
    <exclusion>
	  <artifactId>spring-boot-starter-json</artifactId>
	  <groupId>org.springframework.boot</groupId>
	</exclusion>
  </exclusions>
</dependency>

 此时,需要将依赖改为以下即可:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值