本文介绍了获取异常'无法找到此RouteBuilder参考任何路线:RouteBuilderRef [routebuilderOne]'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到异常无法找到此RouteBuilder参考任何路线:RouteBuilderRef [routebuilderOne] 当我试图连线的基础上配置路由建设者

I am getting the exception Cannot find any routes with this RouteBuilder reference: RouteBuilderRef[routebuilderOne] when I am trying to wire the route builder based on configuration.

路线生成器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

Class file of Route builder 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

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

Is there any other way to achieve the conditional based route selection ?

推荐答案

您需要给 @Component 一个ID,并且不使用类名作为ID。一个Java类的名字应该先从大写。

You need to give the @Component a id, and not use the class name as the id. A java class name should start with upper case.

不知道春天注释可以做到这一点,但也许你可以做 @Component(NAME =routebuilderOne)或东西。

Not sure if the spring annotation can do that, but maybe you can do @Component(name = "routebuilderOne") or something.

这篇关于获取异常'无法找到此RouteBuilder参考任何路线:RouteBuilderRef [routebuilderOne]'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-27 17:17