301.9.5.6. 使用自定义 CamelContextLifecycle


在下面的代码中,我们使用 beforeStartafterStop 将自定义 bean 列在 Simple Registry 中,并在我们停止时进行清理。

然后,我们需要使用名称"CamelContextLifecycle"在 web.xml 文件中注册本课程。该值必须是 FQN,它引用了实施 org.apache.camel.component.servletlistener.CamelContext Life 周期接口的类。

  <context-param>
    <param-name>CamelContextLifecycle</param-name>
    <param-value>org.apache.camel.component.servletlistener.MyLifecycle</param-value>
  </context-param>
Copy to Clipboard Toggle word wrap

我们使用名称"my Bean "列出 HelloBean Bean,我们在 Camel 路由中引用此 Bean,如下所示:

public class MyBeanRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("seda:foo").routeId("foo")
            .to("bean:myBean")
            .to("mock:foo");
    }
}
Copy to Clipboard Toggle word wrap

重要信息: 如果您使用 org.apache.camel.component.servletlistener.JndiCamelServletContextListener,那么 CamelContext Life 周期也必须使用 JndiRegistry。如果 servlet 为 org.apache.camel.component.servletlistener.SimpleCamelServletContextListener,那么 CamelContextLifecycle 必须使用 SimpleRegistry

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat