因此,现在我试图将路由从XML文件导入到Java DSL中。Apache Camel将XML路由和Bean从文件加载到CamelContext中
我一直试图从this link开始,但既然它是一个这样简单的例子,它并没有真正帮助我,也没有指向更复杂的例子。
我的问题是我的骆驼路线使用豆。 PropertiesComponent
和FileIdempotentRepository
以及其他的豆在XML文件中定义,供XML文件中的路由使用。
我原来的Spring配置看起来像下面这样:
<?xml version="1.0" encoding="UTF-8"?>
<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-4.2.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="bean1" class="class1" />
<bean id="bean2" class="class2" />
<bean id="bean3" class="FileIdempotentRepository"> [...] </bean>
<bean id="properties" class="PropertiesComponent"> [...] </bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="{{someplace}}&filter=#bean1" />
<setHeader headerName="FileRepoKey">
<simple>${file:name}-${file:modified}</simple>
</setHeader>
<idempotentConsumer messageIdRepositoryRef="bean3">
<header>FileRepoKey</header>
<process ref="bean2" />
<to uri="{{otherplace}}"/>
</idempotentConsumer>
</route>
</camelContext>
</beans>
那么,如何转换这个烂摊子成由Java DSL从引入路由可用的东西吗?
我明白从我看这个链接,我需要做一些事情,如转换<camelContext>
到<routes>
。但留在豆给我一个错误沿线︰
Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.springframework.org/schema/beans", local:"beans"). Expected elements are [...]
我需要改变什么?或者,我是否可以在XML文件中没有bean,以便通过链接中使用的Java导入它?
问题是您的原始文件是Spring XML上下文..不仅仅是您引用的链接中的XML简单路由。您正试图解决的要求和/或问题是什么?换句话说..你为什么要/需要从XML文件加载路由? –
基本上,老板希望能够快速添加路由而不必编写正确的Java实现。留下新的路线在下一个版本中实施,而不是立即执行。 – Jsmith
Gotcha ..所以我怀疑路线导入专长支持阅读将基本上重新实现Spring的整个bean b/c。如果你阅读页面上的注释..你会发现路由的复杂性是有限制的 - 没有共享异常处理程序,拦截器等等。豆类会落入那个 –