Spring中的Apache Camel RouteBuilder没有启动configure()

时间:2015-07-01 12:18:46

标签: java spring apache-camel

我正在使用Apache Camel在动态端点之间创建路由。我正在使用Main工作,但现在我需要在Apache Tomcat服务器上部署应用程序。他的问题是我的骆驼语境并没有找到我的路线建设者。这是我的applicationContext:

<bean id="myRoute" class="com.ittb.boa.jis.extractor.MyRouteBuilder">
    <constructor-arg name="src" ref="logsFileConnector" />
    <constructor-arg name="dest" ref="elasticSearchConnector" />
</bean>

<camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
    <routeBuilder ref="myRoute" />
</camelContext>

我收到以下错误:

    [         localhost-startStop-1] ContextLoader                  ERROR Context initialization failed
org.apache.camel.RuntimeCamelException: org.apache.camel.CamelException: Cannot find any routes with this RouteBuilder reference: RouteBuilderRef[myRoute]
    at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1619)[camel-core-2.15.2.jar:2.15.2]
    at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:328)[camel-spring-2.15.2.jar:2.15.2]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:773)[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)[spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)[spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)[spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4728)[catalina.jar:8.0.21]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5166)[catalina.jar:8.0.21]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)[catalina.jar:8.0.21]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)[catalina.jar:8.0.21]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)[catalina.jar:8.0.21]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_45]
    at java.lang.Thread.run(Thread.java:745)[:1.8.0_45]
juil. 01, 2015 2:55:15 PM org.apache.catalina.core.StandardContext listenerStart
GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
org.apache.camel.RuntimeCamelException: org.apache.camel.CamelException: Cannot find any routes with this RouteBuilder reference: RouteBuilderRef[myRoute]
    at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1619)
    at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:328)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:773)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4728)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5166)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.camel.CamelException: Cannot find any routes with this RouteBuilder reference: RouteBuilderRef[myRoute]
    at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.installRoutes(AbstractCamelContextFactoryBean.java:832)
    at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.setupRoutes(AbstractCamelContextFactoryBean.java:352)
    at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:326)
    ... 17 more

我试图在MyRouteBuilder中使用configure()上的EndPoint调试它,并且错误出现在断点之前..

这是方法configure()非常重:

public class MyRouteBuilder extends RouteBuilder {
private ConnectorEndPoint src;
private ConnectorEndPoint dest;

int i = 0;
private String CRON_EXPRESSION_QUARTZ = CRONGenerator.generateCRONExpression("0/1", "9-17", "?", "*", "MON-FRI");

private MyProcessor processor = new MyProcessor();
RestConsumerFactory consumerFactory = new RestConsumerFactory() {
    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate, String consumes, String produces, Map<String, Object> parameters) throws Exception {
        return null;
    }
};

public MyRouteBuilder(ConnectorEndPoint src, ConnectorEndPoint dest) {
    this.src = src;
    this.dest = dest;
}

public void configure() {
    if (src instanceof ConnectorSQL){
        from("quartz2://foo?cron="+ CRON_EXPRESSION_QUARTZ)
        .to(src.getRouteFrom())
        .bean(processor, "conversionNumericAndDate")
        .bean(processor, "standardisation")
        .to(dest.getRouteTo());
    } else if (src instanceof ConnectorMongoDB){
        from("quartz2://foo?cron="+ CRON_EXPRESSION_QUARTZ)
        .to(src.getRouteFrom())
        .bean(processor, "convertDBObjectToString")
        //.bean(processor, "conversionNumericAndDate")
        .to(dest.getRouteTo());
    } else if (src instanceof ConnectorREST){
        from("quartz2://foo?cron="+ CRON_EXPRESSION_QUARTZ).to(src.getRouteFrom())
        //.bean(processor, "conversionNumericAndDate")
        //.bean(processor, "standardisation")
        .to(dest.getRouteTo());
    } else if (src instanceof ConnectorXMLFile){
        XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
        xmlJsonFormat.setEncoding("UTF-8");
        xmlJsonFormat.setForceTopLevelObject(true);
        xmlJsonFormat.setTrimSpaces(true);
        xmlJsonFormat.setSkipNamespaces(true);
        xmlJsonFormat.setRemoveNamespacePrefixes(true);         
        from("file:xml?scheduler=quartz2&scheduler.cron="+ CRON_EXPRESSION_QUARTZ)
        .marshal(xmlJsonFormat)
        .to(dest.getRouteTo());
    } else if (src instanceof ConnectorLogsFile){
        ArrayListAggregationStrategy aggregationStrategy = new ArrayListAggregationStrategy();
        from(src.getRouteFrom())
        .bean(processor, "lineFilter(${body}, " + src.getFieldToFilter() +", " + src.getFirstValue() +", " + src.getSecondValue() + ")")
        .split(body().tokenize("\n"))
        .filter().method(MyFilter.class, "isValidError")
        .bean(processor, "processLogsApplicationSource")
        .filter().method(MyFilter.class, "dateFilter(${body}, " + src.getFieldToFilter() +", " + src.getFirstValue() +", " + src.getSecondValue() + ")")
        .aggregate(body(), aggregationStrategy).completionInterval(1000)
        .to(dest.getRouteTo());
    } else {
        System.err.println("Erreur : Type de endpoint en entrée inconnu");
        System.exit(1);
    }
}

所以,它就像驼峰上下文没有启动configure()方法所以没有创建RouteBuilder而且上下文找不到它。我的web.xml是:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.apache.camel.component.servletlistener.SimpleCamelServletContextListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

几点建议:

  1. 检查容器中是否实际创建了RouteBuilder bean。
  2. 你的MyRouteBuilder是否从骆驼延伸RouteBuilder
  3. 为了进一步说明,请提供MyRouteBuilder和完整堆栈跟踪的完整代码。

答案 1 :(得分:0)

问题来自于在RouteBuilder之前使用SimpleRegistry bean的错误。