【发布时间】:2016-07-13 10:17:22
【问题描述】:
我正在考虑两个小型 Spring Boot 应用程序:
- Applcation 1:在http://localhost:8081 上运行的小型 Web 服务,实现了一个简单的 Spring 控制器来响应 /camel 上的 GET 请求。该服务在访问http://localhost:8081/camel 时只返回“Hello world”。
- 应用程序 2:一个小型应用程序,应该向应用程序 1 执行 GET 请求并将响应打印到控制台(在本例中为“Hello world”)。
使用 Springs RestTemplate,我可以在应用程序 2 中轻松实现这个 GET 请求:
RestTemplate template = new RestTemplate();
String response = template.getForBody("http://localhost:8081/camel", String.class);
System.out.println(response);
我现在的目标是使用 Apache Camel 而不是 Spring 的 RestTemplate。
我尝试定义以下 RouteBuilder:
public class MyRoutes extends RouteBuilder {
@Override
public void configure() throws Exception() {
from("jetty:http://localhost:8081/camel").to("direct:processRest");
from("direct:processRest").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
System.out.println(exchange.getIn().getBody());
}
});
}
}
但是,当我运行应用程序时,我收到以下错误:
org.apache.camel.spring.boot.CamelSpringBootInitializationException: java.net.BindException: Address already in use: bind
Spring Boot 或 Apache Camel 会自动尝试在端口 8081 上启动 Jetty 服务器,但其他 Web 服务(应用程序 1)已在此端口上运行。
有人知道如何避免这个问题吗?
【问题讨论】:
标签: web-services spring-boot apache-camel