简体   繁体   中英

Mule: how to assign a Java/Spring bean's method call result to a flow variable

I am new to Mule. I understand I can have"Java" or "Invoke" component in the Mule flow configuration. My question is: how can I assign the value returned by a Java method call to a Mule flow variable? ex. something like

<spring-bean name="myBean" .... />

<invoke object-ref="myBean" method="addTwoNumbers" methodArguments="#[var1], #[var2]" methodArgumentTypes="java.lang.Float, java.lang.Float" name="someName" doc:name="Invoke"/>

<set-variable variableName="addResult" value="???????" />

I need the "addResult" var to have the value of the previous invocation result, but how?

Thanks!

The result of the spring bean will be the payload, so you can set it like so:

<set-variable variableName="addResult" value="#[payload]" />

However if you don't want to overwrite the existing payload you can use an enricher :

<enricher target="#[flowVars.addResult]">
   <invoke object-ref="myBean" method="addTwoNumbers" methodArguments="#[var1], #[var2]" methodArgumentTypes="java.lang.Float, java.lang.Float" name="someName" doc:name="Invoke"/>
</enricher>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM