private void afterDeploymentValidation( @Observes AfterDeploymentValidation adv, BeanManager manager) { Collection<CamelContext> contexts = new ArrayList<>(); for (Bean<?> context : manager.getBeans(CamelContext.class, ANY)) { contexts.add(getReference(manager, CamelContext.class, context)); } // Add type converters to Camel contexts CdiTypeConverterLoader loader = new CdiTypeConverterLoader(); for (Class<?> converter : converters) { for (CamelContext context : contexts) { loader.loadConverterMethods(context.getTypeConverterRegistry(), converter); } } // Add routes to Camel contexts boolean deploymentException = false; Set<Bean<?>> routes = new HashSet<>(manager.getBeans(RoutesBuilder.class, ANY)); routes.addAll(manager.getBeans(RouteContainer.class, ANY)); for (Bean<?> context : manager.getBeans(CamelContext.class, ANY)) { for (Bean<?> route : routes) { Set<Annotation> qualifiers = new HashSet<>(context.getQualifiers()); qualifiers.retainAll(route.getQualifiers()); if (qualifiers.size() > 1) { deploymentException |= !addRouteToContext(route, context, manager, adv); } } } // Let's return to avoid starting misconfigured contexts if (deploymentException) { return; } // Trigger eager beans instantiation (calling toString is necessary to force // the initialization of normal-scoped beans). // FIXME: This does not work with OpenWebBeans for bean whose bean type is an // interface as the Object methods does not get forwarded to the bean instances! eagerBeans.forEach(type -> getReferencesByType(manager, type.getJavaClass(), ANY).toString()); manager .getBeans(Object.class, ANY, STARTUP) .stream() .forEach(bean -> getReference(manager, bean.getBeanClass(), bean).toString()); // Start Camel contexts for (CamelContext context : contexts) { if (ServiceStatus.Started.equals(context.getStatus())) { continue; } logger.info("Camel CDI is starting Camel context [{}]", context.getName()); try { context.start(); } catch (Exception exception) { adv.addDeploymentProblem(exception); } } // Clean-up Stream.of(converters, camelBeans, eagerBeans, cdiBeans).forEach(Set::clear); Stream.of(producerBeans, producerQualifiers).forEach(Map::clear); }