首页 > 解决方案 > Spring Boot:如何检索通过 Exchange Http Get 方法发送的请求对象?

问题描述

我是 SpringBoot 的新手,并试图弄清楚一切是如何工作的。我有一个关于如何从 MicroService2 检索请求对象的值的问题,它作为 HttpEntity 的一部分从 MicroService1 传递。我在 MicroService2 中尝试了@RequestBody ,但是“缺少所需的请求正文,出现错误”。

微服务1

{
  HttpEntity<Object> entity=new HttpEntity<>(requestObject);
  restTemplate.exchange(url,HttpMethod.GET,entity,Object.class);
}

微服务2

@GetMapping("/get-data")
public ResponseObject getResponse( ...... )
{

    // How to Retrieve the requestObject values send from MicroService1 
}

标签: javaspringspring-bootspring-mvc

解决方案


推荐阅读