[英]Apache Camel Java DSL pass class parameter to bean method
I am using Camel 2.13.1 I want to pass a class as parameter to one of my methods in the bean 我正在使用骆驼2.13.1我想将类作为参数传递给Bean中的一种方法
Can I do something like 我可以做类似的事情吗
In Route
--
.beanRef("someSpringBeanRef","someMethod(${body},com.test.TestObject)")
--
And in Bean
public Object someMethod(String testBody, Class type){
I know I can send the qualified class name in header and use it within the bean but it doesn't feel too right. 我知道我可以在标头中发送合格的类名,并在Bean中使用它,但是感觉并不正确。 Are there any other alternatives?
还有其他选择吗?
I saw this link but it did not work for me Apache Camel - Spring DSL - Pass String argument to bean method 我看到了此链接,但对我不起作用Apache Camel-Spring DSL-将String参数传递给bean方法
You can try using the wild card symbol '*'. 您可以尝试使用通配符'*'。 Camel will try to convert parameter to the correct type.
骆驼将尝试将参数转换为正确的类型。
Route: 路线:
public class Routes extends RouteBuilder {
public void configure() throws Exception {
from("direct:in").bean(new TestBean(), "test(*, ${body})");
}
}
Bean: 豆角,扁豆:
public class TestBean {
public void test(Class<?> clazz, String str) {
System.out.println(clazz);
}
}
Camel context: 骆驼语境:
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");
}
Output: 输出:
class java.lang.String
class java.lang.String
A method parameter of type Class
is not supported. 不支持
Class
类型的方法参数。 From the Camel documentation : 从骆驼文档 :
Camel uses the following rules to determine if it's a parameter value in the method option 骆驼使用以下规则来确定它是否为方法选项中的参数值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.