获取异常“无法找到具有此 RouteBuilder 参考的任何路线:RouteBuilderRef[routebuilderOne]" [英] Getting the exception 'Cannot find any routes with this RouteBuilder reference: RouteBuilderRef[routebuilderOne]'

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

问题描述

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

Route Builder 1 的类文件

import org.apache.camel.spring.SpringRouteBuilder;导入 org.springframework.beans.factory.annotation.Autowired;导入 org.springframework.beans.factory.annotation.Value;导入 org.springframework.stereotype.Component;@成分公共类 RoutebuilderOne 扩展 SpringRouteBuilder {@Value("${routebuilder.stream.one}")私有布尔 autoStartupRouteOne;@覆盖公共无效配置()抛出异常{from(source1).autoStartup(autoStartupRouteOne).split().method("splitLogic","splitMethod").to(destination1);}}

Route builder 2 的类文件

import org.apache.camel.spring.SpringRouteBuilder;导入 org.springframework.beans.factory.annotation.Autowired;导入 org.springframework.beans.factory.annotation.Value;导入 org.springframework.stereotype.Component;@成分公共类 RoutebuilderTwo 扩展 SpringRouteBuilder {@Value("${routebuilder.stream.two}")私有布尔型 autoStartupRouteTwo;@覆盖公共无效配置()抛出异常{from(source2).autoStartup(autoStartupRouteTwo).to(destination2);}}

骆驼上下文文件

</豆类>

autoStartupRouteOne,autoStartupRouteTwo 的值,与属性文件中的一样

 autoStartupRouteOne = falseautoStartupRouteTwo = 真

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

解决方案

你需要给 @Component 一个 id,而不是使用类名作为 id.Java 类名应以大写开头.

不确定 spring 注释是否可以做到这一点,但也许你可以做到 @Component(name = "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.

Class file of 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 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);

     }
}

Camel context file

<?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>

Values for autoStartupRouteOne,autoStartupRouteTwo as in the property file

 autoStartupRouteOne = false
 autoStartupRouteTwo = true

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

解决方案

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.

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆