我正在寻找一种方法来构造一个对象并在路径的主体中设置它。假设我的Bean被命名为sample.Person,我需要调用它的一个构造函数Person(name)并将其设置为Body。
像这样:
<bean id="myBean" class="sample.Person"/>
<route id="myroute">
<from uri="timer:foo?repeatCount=1"/>
<setBody>
<simple>${myBean("name")}</simple>
</setBody>
. . . .
<to uri="mock:result"/>
</route>
哪个不幸不起作用..... 任何帮助? 感谢
答案 0 :(得分:2)
首先,我将创建PersonFactory来实例化Person对象:
public class PersonFactory {
public Person createPerson(String name){
return new Person(name);
}
}
然后在骆驼路线中使用它:
<bean id="personFactory" class="sample.PersonFactory" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
.....
<route>
<from uri="timer:foo?repeatCount=1"/>
<setProperty propertyName="personName">
<constant>John Doe</constant>
</setProperty>
<setBody>
<spel>#{@personFactory.createPerson(properties['personName'])}</spel>
</setBody>
. . . .
<to uri="mock:result"/>
</route>
...
<camelContext>