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

标签 java spring spring-boot apache-camel jetty

我有一个带有 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/

相关文章:

java - 匹配以某个路径元素开头的任何 url

java - 如何在Spring框架中实现UDP

ms-access - UCAExc 3.0.7 无效事务状态 : read-only SQL-transaction Sometimes when saving to . accdb

postgresql - 为什么我的 Kubernetes 服务运行在不同的子网上?

java - 当我猜错单词时,为什么我的菜单不显示?

java - 如何创建表示 Java long 的字符串,就好像它是无符号的 64 位值一样

java - Maven打包后出错

java - Collectors.toList() 显示错误 "Expected 3 argument but found 1"

java - 为 MongoDB 淘汰 Hibernate/Mysql 或为 Java/Spring/Tomcat Web 应用程序淘汰 Couch

java - Spring Webflux WebFilterChain 中的 URL 模式过滤