如何将 Spring Boot 中的 Jetty 与 Camel Jetty 组件一起使用? [英] How to use Jetty from Spring Boot with Camel Jetty Component?
问题描述
我有一个带有骆驼端点路由的 Spring Boot 应用程序,使用骆驼码头组件作为网关.
I have a Spring Boot application with Camel Endpoints routes using camel jetty component as a gateway.
@Component
public class StartEcommerce extends RouteBuilder {
@Override
public void configure() throws Exception {
restConfiguration()
.host("localhost")
.port(8085);
rest("/rest/v1")
.post("/order")
.to("direct:ecommerceRestRoute")
.post("/cancelEnrollment")
.to("direct:cancelEnrollmentRestRoute");
// other routes ...
}
}
如果我将 jetty 组件放在端口 8085 中执行,则一切正常.
Everything works fine if I put the jetty component to execute in port 8085.
但是,我想使用已经在端口 8081 中运行的 Spring Boot 码头,因为我想从执行器访问健康检查端点并能够像这样调用我的休息端点:
However, I would like to use Spring Boot's jetty that is already running in port 8081, because I want to have access to healthcheck endpoints from actuator and be able to call my rest endpoints like this:
localhost:8081/health
localhost:8081/rest/v1/order
localhost:8081/rest/v1/cancelEnrollment
尝试关注此讨论
在spring boot中使用现有的http服务器作为camel端点
但是我得到了下面的错误,因为我有两个 Jettys 在同一个端口上运行
but I got the error below, because I have two Jettys running on the same port
***************************
APPLICATION FAILED TO START
***************************
Description:
Embedded servlet container failed to start. Port 8081 was already in use.
Action:
Identify and stop the process that's listening on port 8081 or configure this application to listen on another port.
我使用的是骆驼码头 2.18.0 和 Spring Boot 1.4.2.RELEASE.
I'm using camel-jetty 2.18.0 an Spring Boot 1.4.2.RELEASE.
对如何实现这一目标有什么建议吗?
Any suggestions how can I achieve this?
推荐答案
我找到了解决方案,我的 build.gradle 中的依赖项设置不正确.
I found the solution, I have a incorrect dependency set in my build.gradle.
compile('org.apache.camel:camel-jetty:2.18.0')
此外,我从路由中删除了其余配置:
Besides I remove the rest configuration from my route:
restConfiguration()
.host("localhost")
.port(8081);
并遵循克劳斯·易卜生的这个例子
And follow this example from Claus Ibsen
这篇关于如何将 Spring Boot 中的 Jetty 与 Camel Jetty 组件一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!