获取异常 'Cannot find any routes with this RouteBuilder reference: RouteBuilderRef[routebuilderOne]'

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

当我尝试根据配置连接路由构建器时出现异常 Cannot find any routes with this RouteBuilder reference: RouteBuilderRef[routebuilderOne]

Class Route Builder 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);

     }
}

Class 路径生成器文件 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

有没有其他方法可以实现基于条件的路由选择?

您需要给@Component一个id,而不是使用class名字作为id。 java class 名称应以大写开头。

不确定 spring 注释是否可以做到这一点,但也许你可以做到 @Component(name = "routebuilderOne") 或其他东西。

我遇到了同样的异常。不同之处在于我的代码一直在工作,然后似乎 运行 突然停止了。我们可能已经升级了骆驼版本,但我不确定。无论哪种方式,为了修复它,我只是停止了 karaf,然后 运行 带有 clean 选项的启动脚本。之后一切都很好。 希望这对其他人有帮助。