gpt4 book ai didi

java - 如何通过 Camel Jetty 组件使用 Spring Boot 中的 Jetty?

转载 作者:行者123 更新时间:2023-12-01 08:52:23 24 4
gpt4 key购买 nike

我有一个带有 Camel Endpoints 路由的 Spring Boot 应用程序,使用 Camel jetty 组件作为网关。

@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 中执行,则一切正常。

但是,我想使用已经在端口 8081 中运行的 Spring Boot 的 jetty,因为我希望能够从执行器访问运行状况检查端点,并能够像这样调用我的其余端点:

localhost:8081/health
localhost:8081/rest/v1/order
localhost:8081/rest/v1/cancelEnrollment

尝试关注此讨论

Use existing http server in spring boot as camel endpoint

但我收到以下错误,因为我有两个 Jetty 在同一端口上运行

***************************
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.

我使用的是camel-jetty 2.18.0和Spring Boot 1.4.2.RELEASE。

有什么建议我可以如何实现这一目标吗?

最佳答案

我找到了解决方案,我的 build.gradle 中设置了不正确的依赖项。

compile('org.apache.camel:camel-jetty:2.18.0')

此外,我从 route 删除了其余配置:

restConfiguration()
.host("localhost")
.port(8081);

并遵循克劳斯·易卜生的这个例子

https://github.com/camelinaction/camelinaction2/blob/master/chapter7/springboot-camel/src/main/java/camelinaction/HelloRoute.java

关于java - 如何通过 Camel Jetty 组件使用 Spring Boot 中的 Jetty?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42305684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com