你可以在短短一个骆驼语境中添加外部XML文件定义了许多骆驼路线 为波纹管的例子:
您可以在一个新的XML文件中创建你的路由(即routes1-config.xml中):
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<!-- this is an included XML file where we only the the routeContext -->
<routeContext id="routes1" xmlns="http://camel.apache.org/schema/spring">
<!-- we can have a route -->
<route id="cool">
<from uri="direct:start"/>
<to uri="mock:result"/>
</route>
<!-- and another route, you can have as many your like -->
<route id="bar">
<from uri="direct:bar"/>
<to uri="mock:bar"/>
</route>
</routeContext>
</beans>
然后导入,并引用它的主要骆驼XML文件中的情况下,像这样的:
<!-- import the routes from another XML file -->
<import resource="routes1-config.xml"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<!-- refer to a given route to be used -->
<routeContextRef ref="routes1"/>
<!-- we can of course still use routes inside camelContext -->
<route id="inside">
<from uri="direct:inside"/>
<to uri="mock:inside"/>
</route>
</camelContext>
欲了解更多详情,请从Apache的骆驼检查的官方参考文档http://camel.apache.org/how-do-i-import-routes-from-other-xml-files.html
非常感谢您的答复皮特!但我该怎么做?基本上我有一个属性文件,我定义了一个RouteBuilder类的列表。然后路由中的代码迭代该文件。我想要的是具有RouterBuilder类列表的同一个文件,但是在它自己的Camel上下文中创建每个RouteBuilder。那可能吗?可能以某种方式修改CamelConfiguration类,但我不知道如何去做。再次感谢! – 2014-10-02 13:21:53