Mule - Spring - 将属性传递给Java类

时间:2016-02-28 11:05:58

标签: java spring properties mule

这是我的骡子流:

<spring:beans>

    <spring:bean id="component" name="component" lazy-init="false" class="java.delete.DeleteFiles">
        <spring:property name="messageJSON" value="#[message.payloadAs(java.lang.String)]"/>
    </spring:bean>

</spring:beans>

<flow name="javatestFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
    <set-payload value="#[message.payloadAs(java.lang.String)]" doc:name="Set Payload"/>
    <set-property propertyName="message" value="#[message.payloadAs(java.lang.String)]" doc:name="Property"/>
    <component doc:name="Java">
        <spring-object bean="component"/>
    </component>
</flow>

在我的Java课程中,我实现了来自Mule的Callable class

public class DeleteFiles implements Callable {

    public String messageJSON;

    public String getmessageJSON() {
        return messageJSON;
    }

    public void setmessageJSON(String messageJSON) {
        this.messageJSON = messageJSON;
    }

    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
        System.out.println(messageJSON);

        String msj = eventContext.getSession().getProperty("messageJSON");
        System.out.println(msj);

        return null;
    }

}

第一个SysOut回复我:

  

[message.payloadAs(java.lang.String中)]

第二个:

  

如何使用Spring和Java从我的mule流中的属性中获取值?

1 个答案:

答案 0 :(得分:0)

解决方案是在Java中使用OutboundProperty

    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
        String propertyDir = eventContext.getMessage().getOutboundProperty("messageJSON");
        System.out.println(propertyDir);
        return null;
    }