300.9. ServletListener Component

可从 Camel 2.11 开始

此组件用于引导 Web 应用程序中 Camel 应用程序。例如,您必须先找到自己的引导 Camel 的方式,或者依赖 Spring 等第三方框架来完成它。

注意

侧边栏 (侧边栏)支持 Servlet 2.x onwards,这意味着它也在较旧的 Web 容器中工作;这是此组件的目标。虽然 Servlet 2.x 需要使用 web.xml 文件作为配置。对于 Servlet 3.x 容器,您可以使用注解驱动的配置来利用 @WebListener 增加 Camel,并在您提升 Camel 时实施您自己的类。这样做仍然会面临如何让最终用户轻松配置 Camel,通过旧学校 web.xml 文件可以免费获取这些挑战。

Maven 用户需要将以下依赖项添加到其 pom.xml 中:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-servletlistener</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

300.9.1. 使用

您需要选择以下一种提取类 org.apache.camel.component.servletlistener.CamelServletContextListener

  • JndiCamelServletContextListener 使用 JndiRegistry 为其 registry 使用 JNDI。
  • SimpleCamelServletContextListener,它使用 SimpleRegistry 来利用 java.util.Map 作为其 registry。

要使用此目的,您需要在 WEB-INF/web .xml 文件中配置 org.apache.camelServletContextListener,如下所示: