1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package com.gct.tools.etlcamelhuge.camelconfig;
- import lombok.SneakyThrows;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.camel.CamelContext;
- import org.apache.camel.CamelContextAware;
- import org.apache.camel.builder.RouteBuilder;
- import org.apache.camel.impl.engine.DefaultCamelContextNameStrategy;
- import org.springframework.beans.BeansException;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.ApplicationContextAware;
- import org.springframework.context.annotation.Configuration;
- import java.util.Map;
- /**
- * class name: CamelContextAwareConfiguration
- *
- * @author lloyd
- * @version 1.0
- * @since 2021/4/14 下午5:28
- */
- @Slf4j
- @Configuration
- public class CamelContextAwareConfiguration implements CamelContextAware, ApplicationContextAware {
- private CamelContext camelContext;
- private ApplicationContext applicationContext;
- @SneakyThrows
- @Override
- public void setCamelContext(CamelContext cc) {
- this.camelContext = cc;
- camelContext.setNameStrategy(new DefaultCamelContextNameStrategy("lloyd-camel-etl"));
- final Map<String, RouteBuilder> beans = applicationContext.getBeansOfType(RouteBuilder.class);
- log.info("[I say:] total {} defined route builders ", beans.size());
- for (RouteBuilder value : beans.values()) camelContext.addRoutes(value);
- }
- @Override
- public CamelContext getCamelContext() {
- return camelContext;
- }
- @Override
- public void setApplicationContext(ApplicationContext appContext) throws BeansException {
- applicationContext = appContext;
- }
- }
|