当前位置: 首页 > 知识库问答 >
问题:

Spring中的Apache Camel RouteBuilder不启动configure()

茹展鹏
2023-03-14
<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>

谢谢你的帮助!

共有1个答案

皮景龙
2023-03-14

几点建议:

  1. 检查RouteBuilderbean是否实际在容器中创建。
  2. 您的MyRouteBuilder是否从Camel扩展RouteBuilder

为了获得更多的澄清,请提供MyRouteBuilder的完整代码和完整的StackTrace。

 类似资料:
  • 我最近开始使用,发现它非常有趣。由于我的大多数应用程序都在中,我决定使用团队提供的spring boot starter项目进行快速设置。它附带了autoconf-spring设置,这使得查询endpoint更加容易。 在IDEA中花了几个小时进行项目设置后,我能够运行graphql示例应用程序。但我认为我的servlet仍然没有启用,只有endpoint正在运行,因为默认查询返回。 这是: 这就

  • 在Spring Boot 2.2.0中,“httptrace”执行器endpoint不再存在。如何恢复此功能?

  • 在我的Spring Boot应用程序中,我从Thymeleaf切换到JSP,它在我的本地计算机上正常工作,但当我将它上传到Heroku服务器时,我发现出现了一个意外错误(type=notfound,status=404)/WEB-INF/jsp/home。jsp 它的罐子打包,如果它在本地工作,但不是在Heroku服务器上,这意味着什么?

  • 我在intellij上启动spring boot应用程序时遇到问题,它失败了,并显示以下消息:与目标VM断开连接,地址:'127.0.0.1:49784',传输:'socket' 过程结束,退出代码为255。以前有人遇到过这种情况吗?

  • 我需要在spring boot data rest api中启用全局CORS,以防止在从浏览器调用api时出现以下错误:http://localhost:8090/posts?user-id=1。请求的资源上没有“访问-控制-允许-来源”标头。因此,不允许访问源“http://localhost”。“ 我可以在a浏览器中键入url并接收该资源的正确get响应,但我不能从网页中的ajax调用中发出相

  • 问题内容: 我一直在研究Spring / Spring MVC应用程序,并且希望添加性能指标。我遇到过Spring Boot Actuator,它看起来是一个不错的解决方案。但是我的应用程序不是Spring Boot应用程序。我的应用程序在传统容器Tomcat 8中运行。 我添加了以下依赖 我创建了以下配置类。 我什至可以按照StackOverflow另一篇文章的建议在每个配置类上添加 问题答案: