[英]Apache Camel - Spring DSL - Pass String argument to bean method
[英]Apache Camel Java DSL pass class parameter to bean method
我正在使用駱駝2.13.1我想將類作為參數傳遞給Bean中的一種方法
我可以做類似的事情嗎
In Route
--
.beanRef("someSpringBeanRef","someMethod(${body},com.test.TestObject)")
--
And in Bean
public Object someMethod(String testBody, Class type){
我知道我可以在標頭中發送合格的類名,並在Bean中使用它,但是感覺並不正確。 還有其他選擇嗎?
我看到了此鏈接,但對我不起作用Apache Camel-Spring DSL-將String參數傳遞給bean方法
您可以嘗試使用通配符'*'。 駱駝將嘗試將參數轉換為正確的類型。
路線:
public class Routes extends RouteBuilder {
public void configure() throws Exception {
from("direct:in").bean(new TestBean(), "test(*, ${body})");
}
}
豆角,扁豆:
public class TestBean {
public void test(Class<?> clazz, String str) {
System.out.println(clazz);
}
}
駱駝語境:
public static void main(String[] args) throws Exception {
CamelContext ctx = new DefaultCamelContext();
ctx.addRoutes(new Routes());
ctx.start();
ctx.createProducerTemplate().sendBody("direct:in", String.class);
ctx.createProducerTemplate().sendBody("direct:in", "java.lang.String");
}
輸出:
class java.lang.String
class java.lang.String
不支持Class
類型的方法參數。 從駱駝文檔 :
駱駝使用以下規則來確定它是否為方法選項中的參數值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.