[英]Apache Camel: setProperty and Groovy
我有以下駱駝路線:
<route id="myroute">
<from uri="timer://runOnce?repeatCount=1&delay=10" />
<!-- Set a new property on the exchange. -->
<to uri="bean:propSetter?method=setProp" />
<to uri="direct:fizz" />
</route>
我的PropSetter
bean:
public class PropSetter {
// Add new "buzz" ArrayList<Long> to the exchange.
public void setProp(Exchange exchange) {
exchange.setProperty("buzz", new ArrayList<Long>());
}
}
我想不用Java Bean來重寫它,而是使用Camel的<setProperty/>
元素。 我唯一能想到的就是使用內置的Groovy表達式:
<route id="myroute">
<from uri="timer://runOnce?repeatCount=1&delay=10" />
<!-- Set a new property on the exchange. -->
<setProperty propertyName="buzz">
<groovy>new ArrayList<Long>();</groovy>
</setProperty>
<to uri="direct:fizz" />
</route>
但這似乎不起作用。 那么,如何在調用buzz
的交換中使用XML來設置新的ArrayList<Long>
呢?
使用Spring的util命名空間將列表定義為:
<util:list id="myList" value-type="java.lang.String">
</util:list>
然后,您可以使用簡單的語言訪問Bean並在exchange屬性中進行設置
<camel:setProperty propertyName="buzz">
<camel:simple>${bean:myList}</camel:simple>
</camel:setProperty>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.