获取例外“无法找到该RouteBuilder参考任何路线:RouteBuilderRef [rout

2019-10-21 14:19发布

我得到异常Cannot find any routes with this RouteBuilder reference: RouteBuilderRef[routebuilderOne]当我试图连线根据配置的路由建设者。

路线生成器1的类文件

import org.apache.camel.spring.SpringRouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class RoutebuilderOne extends SpringRouteBuilder {
     @Value("${routebuilder.stream.one}")
     private boolean                 autoStartupRouteOne;

     @Override
     public void configure() throws Exception {
          from(source1).autoStartup(autoStartupRouteOne).split().method("splitLogic","splitMethod").to(destination1);

     }
}

路线建设者2的类文件

import org.apache.camel.spring.SpringRouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class RoutebuilderTwo extends SpringRouteBuilder {
     @Value("${routebuilder.stream.two}")
     private boolean                autoStartupRouteTwo;

     @Override
     public void configure() throws Exception {
        from(source2).autoStartup(autoStartupRouteTwo).to(destination2);

     }
}

骆驼上下文文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
   http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context.xsd
   http://camel.apache.org/schema/spring 
   http://camel.apache.org/schema/spring/camel-spring.xsd">

   <camelContext xmlns="http://camel.apache.org/schema/spring">
       <routeBuilder ref="routebuilderOne"/>
       <routeBuilder ref="routebuilderTwo"/>
   </camelContext>

   <context:component-scan
    base-package="com.hurix.routebuilders" />
 </beans>

autoStartupRouteOne,autoStartupRouteTwo作为属性文件

 autoStartupRouteOne = false
 autoStartupRouteTwo = true

是否有任何其他的方式来实现条件基于路由选择?

Answer 1:

你需要给@Component一个ID,而不是使用类名作为id。 一个Java类的名称应以大写字母开头。

不知道如果弹簧注释可以做到这一点,但也许你可以做@Component(name = "routebuilderOne")什么的。



Answer 2:

我得到相同的异常。 不同的是,我的代码一直在努力,然后似乎随机停止。 我们可能已经升级的骆驼版本,但我不知道。 无论哪种方式,要解决它,我干脆停止karaf,然后跑了清理选项启动脚本。 其后的内容加载的罚款。 希望这可以帮助别人。



文章来源: Getting the exception 'Cannot find any routes with this RouteBuilder reference: RouteBuilderRef[routebuilderOne]'