问题描述
当我尝试根据配置连接路由构建器时,出现异常 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
<?
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]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!