问题
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