How to use Jetty from Spring Boot with Camel Jetty Component?

淺唱寂寞╮ 提交于 2020-05-18 05:25:33

问题


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

}

Everything works fine if I put the jetty component to execute in port 8085.

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

Tried to follow this discussion

Use existing http server in spring boot as camel endpoint

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.

I'm using camel-jetty 2.18.0 an Spring Boot 1.4.2.RELEASE.

Any suggestions how can I achieve this?


回答1:


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

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



来源:https://stackoverflow.com/questions/42305684/how-to-use-jetty-from-spring-boot-with-camel-jetty-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!