279.8.5.6. カスタム CamelContextLifecycle の使用
以下のコードでは、beforeStart
および afterStop
のコールバックを使用して Simple Registry にカスタム Bean を表示し、停止時にクリーンアップします。
次に、パラメーター名 "CamelContextLifecycle" を使用して、web.xml ファイルにこのクラスを登録する必要があります。この値は、org.apache.camel.component.servletlistener.CamelContextLifecycle
インターフェースを実装するクラスを参照する FQN である必要があります。
<context-param> <param-name>CamelContextLifecycle</param-name> <param-value>org.apache.camel.component.servletlistener.MyLifecycle</param-value> </context-param>
「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"); } }
重要: org.apache.camel.component.servletlistener.JndiCamelServletContextListener
を使用する場合、CamelContextLifecycle
も JndiRegistry
を使用する必要があります。サーブレットが org.apache.camel.component.servletlistener.SimpleCamelServletContextListener
の場合には、CamelContextLifecycle
が SimpleRegistry
を使用する必要があります。