300.9.5.6. 사용자 정의 CamelContextLifecycle 사용

아래 코드에서는 콜백 beforeStartafterStop 을 사용하여 Simple Registry에 사용자 지정 빈을 적용하고, 중지하면 정리합니다.

그런 다음 매개변수 이름 "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 "이라는 이름을 사용하여 Hello Bean Bean을 적용함에 따라 다음과 같이 Camel 경로에서 이 빈을 참조할 수 있습니다.

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 를 사용하는 경우 CamelContextLifecycleJndiRegistry 를 사용해야 합니다. 마찬가지로 서블릿이 org.apache.camel.component.servletlistener.SimpleCamelServletContextListener 인 경우 CamelContextLifecycleSimpleRegistry를 사용해야 합니다.