在spring boot中使用现有的http服务器作为camel端点

我有一个使用spring boot starter web的spring boot应用程序。 这将创建一个正在运行的Tomcat实例,并设置在端口上运行的http服务器。 在我的骆驼路线中,我想使用这个http服务器作为http请求的组件,但我无法弄清楚如何利用它。 我看到很多配置jetty实例并从中消耗的例子,但是实际上我不会运行两个http服务器吗? 我只想要一个。 我假设http服务器已经自动assembly,因为我可以使用其他弹簧代码(例如RestController)从中消耗它,我也可以看到它在我的spring启动日志中启动。

@Component public class ExampleRoute extends RouteBuilder { @Override public void configure() throws Exception { //@formatter:off from(  ) .log( LoggingLevel.INFO, log, "Hello World!" ); //@formatter:on } } 

这里有一个例子: https : //github.com/camelinaction/camelinaction2/tree/master/chapter7/springboot-camel

您可以注册使用Spring Boot设置Camel Servlet的ServletRegistrationBean

 @Bean ServletRegistrationBean camelServlet() { // use a @Bean to register the Camel servlet which we need to do // because we want to use the camel-servlet component for the Camel REST service ServletRegistrationBean mapping = new ServletRegistrationBean(); mapping.setName("CamelServlet"); mapping.setLoadOnStartup(1); // CamelHttpTransportServlet is the name of the Camel servlet to use mapping.setServlet(new CamelHttpTransportServlet()); mapping.addUrlMappings("/camel/*"); return mapping; } 

但是对于Camel 2.19,我们计划使这更简单和OOTB: https : //issues.apache.org/jira/browse/CAMEL-10416

然后你就可以做到

 from("servlet:foo") .to("bean:foo"); 

调用Camel路由的HTTP url将是http:localhost:8080/camel/foo