当前位置: 代码迷 >> 综合 >> No converter found for return value of type
  详细解决方案

No converter found for return value of type

热度:95   发布时间:2023-12-18 00:14:07.0

启动各个微服务模块后,启动消费者,访问网址http://localhost/consumer/dept/list
出现500错误。
上网查原因:是因为其他服务没启动成功。
于是查看错误:
Spring Boot Application: No converter found for return value of type
解决方法:
在pom里面添加:

<!-- 对象与JSON之间相互转换 -->
<dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId><version>2.7.3</version>
</dependency>
<dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.7.3</version>
</dependency>
<dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.23</version>
</dependency>

controller:

package com.atguigu.springcloud.controller;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;import com.atguigu.springcloud.entities.Dept;@RestController
public class DeptController_Consumer
{//private static final String REST_URL_PREFIX = "http://localhost:8001";private static final String REST_URL_PREFIX = "http://MICROSERVICECLOUD-DEPT";@Autowiredprivate RestTemplate restTemplate;@RequestMapping(value="/consumer/dept/add")public boolean add(Dept dept){return restTemplate.postForObject(REST_URL_PREFIX+"/dept/add", dept, Boolean.class);}@RequestMapping(value="/consumer/dept/get/{id}")public Dept get(@PathVariable("id") Long id){return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/"+id, Dept.class);}@SuppressWarnings("unchecked")@RequestMapping(value="/consumer/dept/list")public List<Dept> list(){return restTemplate.getForObject(REST_URL_PREFIX+"/dept/list", List.class);} 
}

在次访问成功:
在这里插入图片描述

  相关解决方案