59.14. 게으름 / 프로그래밍 방식 조회
CDI 프로그래밍 모델의 경우 애플리케이션 초기화 시 발생하는 안전한 유형 확인 메커니즘을 선호하지만, 프로그래밍 방식의 조회 메커니즘을 사용하여 애플리케이션을 실행하는 동안 나중에 동적 / 지연 주입을 수행할 수 있습니다.
Camel CDI는 Camel 프리미티브의 표준 주입에 사용할 수 있는 CDI에 해당하는 주석 리터럴을 편리하게 제공합니다. 이러한 주석 리터럴은 lazy injection / programmatic lookup을 수행하기 위해 CDI 진입점인 javax.enterprise.inject.Instance 인터페이스와 함께 사용할 수 있습니다.
예를 들어, @Uri 의 제공된 주석 리터럴을 사용하여 Camel 프리미티브를 지연 조회할 수 있습니다(예: ProducerTemplate 의 경우).
@Any
@Inject
Instance<ProducerTemplate> producers;
ProducerTemplate inbound = producers
.select(Uri.Literal.of("direct:inbound"))
.get();
또는 Endpoint Beans의 경우 다음과 같습니다.
@Any
@Inject
Instance<Endpoint> endpoints;
MockEndpoint outbound = endpoints
.select(MockEndpoint.class, Uri.Literal.of("mock:outbound"))
.get();
마찬가지로 @ContextName 의 제공된 주석 리터럴을 사용하여 CamelContext Beans에 lazily 조회할 수 있습니다. 예를 들면 다음과 같습니다.
@Any
@Inject
Instance<CamelContext> contexts;
CamelContext context = contexts
.select(ContextName.Literal.of("foo"))
.get();
Camel 컨텍스트 유형에 따라 선택 사항을 구체화할 수도 있습니다. 예를 들면 다음과 같습니다.
@Any
@Inject
Instance<CamelContext> contexts;
// Refine the selection by type
Instance<DefaultCamelContext> context = contexts.select(DefaultCamelContext.class);
// Check if such a bean exists then retrieve a reference
if (!context.isUnsatisfied())
context.get();
또는 다음과 같은 다양한 Camel 컨텍스트를 반복합니다.
@Any
@Inject
Instance<CamelContext> contexts;
for (CamelContext context : contexts)
context.setUseBreadcrumb(true);