Use existing http server in spring boot as camel endpoint

为君一笑 提交于 2019-12-03 21:36:51

There is an example here: https://github.com/camelinaction/camelinaction2/tree/master/chapter7/springboot-camel

You can to register a ServletRegistrationBean that setup the Camel Servlet with Spring Boot.

@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;
}

However for Camel 2.19 we plan on make this simpler and OOTB: https://issues.apache.org/jira/browse/CAMEL-10416

And then you can do

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

Where the HTTP url to call that Camel route will be http:localhost:8080/camel/foo

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