Camel Jetty 使用 Spring 引导端口

Camel Jetty to use Spring Boot port

我正在使用 apache camel 构建一个 spring 启动应用程序。我希望我的 rest() 骆驼 DSL 监听与 spring 引导启动时相同的端口。

我尝试遵循此 link 但无法在不使用 servlet 组件的情况下解决它。我不希望我的路线看起来像 servlet:/hello 而是想直接使用码头 (jetty:http://0.0.0.0:0/hello)

我可以正常启动服务器,但没有路由。

调用 http://localhost:8080/hello 无效。

日志

 Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [org.apache.camel.spring.boot.CamelAutoConfiguration] is not eligible for getting processed by all BeanPos
 Logging initialized @1690ms to org.eclipse.jetty.util.log.Slf4jLog
 Server initialized with port: 8080
 jetty-9.4.27.v20200227; built: 2020-02-27T18:37:21.340Z; git: a304fd9f351f337e7c0e2a7c28878dd536149c6c; jvm 1.8.0_221-b11
 Initializing Spring embedded WebApplicationContext
 Root WebApplicationContext: initialization completed in 733 ms
 DefaultSessionIdManager workerName=node0
 No SessionScavenger set, using defaults
 node0 Scavenging every 660000ms
 Started @1882ms
 Initializing ExecutorService 'applicationTaskExecutor'
 Detected and using LURCacheFactory: camel-caffeine-lrucache
 LiveReload server is running on port 35729
 Loading additional Camel XML routes from: classpath:camel/*.xml
 Loading additional Camel XML rests from: classpath:camel-rest/*.xml
 JMX is enabled
 Apache Camel 3.2.0 (CamelContext: ServicesRest) is starting
 StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
 Route: route1 started and consuming from: direct://getCustomer
 jetty-9.4.27.v20200227; built: 2020-02-27T18:37:21.340Z; git: a304fd9f351f337e7c0e2a7c28878dd536149c6c; jvm 1.8.0_221-b11
 Started o.e.j.s.ServletContextHandler@79c2e942{/,null,AVAILABLE}
 Started ServerConnector@11d5056{HTTP/1.1, (http/1.1)}{0.0.0.0:63660}
 Started @2441ms
 Route: route2 started and consuming from: jetty:http://0.0.0.0:0/hello
 Total 2 routes, of which 2 are started
 Apache Camel 3.2.0 (CamelContext: ServicesRest) started in 0.043 seconds
 Initializing Spring DispatcherServlet 'dispatcherServlet'
 Initializing Servlet 'dispatcherServlet'
 Completed initialization in 3 ms
 Started ServerConnector@436343c0{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
 Jetty started on port(s) 8080 (http/1.1) with context path '/'
 Started CamelMicroservicesApplication in 1.688 seconds (JVM running for 2.462)

路线生成器

@Component
public class SimpleRouteBuilder extends RouteBuilder {

    @Override
    public void configure() throws Exception {

        rest("/").get("hello")
            .produces("text/plain")
            .to("direct:getCustomer")

            .outType(String.class);

        from("direct:getCustomer")
                .log(LoggingLevel.INFO, "${body}");

    }
}

build.gradle

dependencies {
    implementation ('org.springframework.boot:spring-boot-starter-web') {
        exclude group: 'org.springframework.boot', module:'spring-boot-starter-tomcat'
    }
    implementation 'org.springframework.boot:spring-boot-starter-jetty'
    implementation 'org.apache.camel.springboot:camel-spring-boot-starter:3.2.0'
    implementation 'org.apache.camel.springboot:camel-rest-starter:3.2.0'
    implementation 'org.apache.camel:camel-jetty:3.2.0'
   }
}

如果你设置 Spring 引导使用任何 HTTP 服务器(tomcat、jetty、undertow)并且你想将其用作 Camel Rest DSL 的一部分,那么你应该使用 camel-servlet -starter 使用 servlet 与 Spring 启动 HTTP 服务器集成。