获取异常“找不到任何具有此 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] 出现异常.

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.

Route Builder 1 的类文件

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);

     }
}

Route builder 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.

不确定 spring 注释是否可以做到这一点,但也许你可以做 @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]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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