问题描述
使用骆驼3.5.0。
我需要为一个属性设置一个值,经过一些转换后,在通过骆驼的方法bean
进行的方法调用中,将该属性用作参数。
from("direct:route1")
.setProperty("myProperty",method(MyBean.class,"myMethod"))
.transform(method(transformerBean,"transformMethod"))
.bean(MyBean.class,"otherMethod(<<HERE I WANT TO PASS THE PREVIoUSLY SET PROPERTY 'myProperty'>>)")
.to("direct:route2");
还有另一种选择。如果我也使用Camel的setProperty
,而不是使用setHeader
方法,则使用该标头作为参数的方法是${headers.nameOfheaderKey}
。这是一种魅力。但是,当我尝试使用“属性”功能时,没有办法检索它并将其作为方法参数传递。
换句话说,当我尝试这样做时:${properties.myProperty}
,我收到此错误:
Caused by: org.apache.camel.language.simple.types.SimpleParserException: UnkNown function: properties.myProperty
at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createSimpleExpression(SimpleFunctionExpression.java:247)
at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createExpression(SimpleFunctionExpression.java:54)
at org.apache.camel.language.simple.ast.SimpleFunctionStart.doCreateLiteralExpression(SimpleFunctionStart.java:69)
at org.apache.camel.language.simple.ast.SimpleFunctionStart.createExpression(SimpleFunctionStart.java:59)
at org.apache.camel.language.simple.SimpleExpressionParser.createExpressions(SimpleExpressionParser.java:164)
at org.apache.camel.language.simple.SimpleExpressionParser.doParseExpression(SimpleExpressionParser.java:87)
at org.apache.camel.language.simple.SimpleExpressionParser.parseExpression(SimpleExpressionParser.java:54)
... 98 common frames omitted
有什么主意吗?
解决方法
Exchange属性的语法为${exchangeProperty.myProperty}
。
exchangeProperty.foo |对象请参考交易所的foo属性