【发布时间】:2020-07-01 21:15:44
【问题描述】:
我正在从 Spring Boot 控制器调用骆驼路线。骆驼路线调用返回字符串值的 REST 服务,我试图将该值从骆驼路线返回到控制器。下面是 Spring Boot 控制器:
@RestController
@RequestMapping("/demo/client")
public class DemoClientController {
@Autowired private ProducerTemplate template;
@GetMapping("/sayHello")
public String sayHello() throws Exception {
String response = template.requestBody("direct:sayHelloGet", null, String.class);
return response;
}
}
下面是我的骆驼路线:
@Component
public class MyRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:sayHelloGet")
.log("Route reached")
.setHeader(Exchange.HTTP_METHOD, simple("GET"))
.to("http://localhost:8080/demo/sayHello")
.log("${body}");
}
}
在路由中,日志正在打印来自 REST 服务的返回值,但该字符串并未返回给控制器。谁能建议如何将值返回给 Spring Boot 控制器?
我使用的 Spring Boot 版本是 2.2.5,Apache Camel 版本是 3.0.1。
【问题讨论】: