简体   繁体   English

Mule-在Mule流中设置弹簧对象调用的属性

[英]Mule - Set properties on spring object call in Mule flow

I'm using Mule 3.3.CE 我正在使用Mule 3.3.CE

I have a Class called SpringObject which implements Callable interface 我有一个名为SpringObject的类,该类实现Callable接口

package com.threads.test;

import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;

public class SpringObject implements Callable {

    private String someData;
    public String getSomeData() {
        return someData;
    }

    public void setSomeData(String someData) {
        this.someData = someData;
    }

    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
        System.out.println("CALL SPRING --->>"+someData);

        return eventContext.getMessage();
    }

}    

And my flow is 我的流程是

<http:connector name="httpConnectorEntryPoint" doc:name="HTTP\HTTPS"/>

<spring:beans xmlns="http://www.springframework.org/schema/beans">
<spring:bean id="component" name="component" class="com.threads.test.SpringObject" lazy-init="false">   
</spring:bean>
</spring:beans>
<flow name="TestThreadsFlow1" doc:name="TestThreadsFlow1">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8099" path="m" connector-ref="httpConnectorEntryPoint" doc:name="HTTP"/>
        <set-payload value="#[&quot;ExitA&quot;]" doc:name="Set Payload"/>
        <component doc:name="Java">
            <spring-object bean="component">
                <property key="someData" value="Information"/>
            </spring-object>
        </component>
    </flow>

The problem is that when I run my flow and use the http connector, the console shows 问题是当我运行流程并使用http连接器时,控制台会显示

CALL SPRING --->>null 呼叫春天--- >>空

instead of 代替

CALL SPRING --->>Information 呼叫弹簧--- >>信息

What could be? 可能是什么?

you can try to configure your spring bean outside the flow as follow: 您可以尝试按以下步骤在流程之外配置spring bean:

<spring:bean id="component" name="component"
    class="com.threads.test.SpringObject" lazy-init="false">
    <spring:property name="someData" value="Information" />
</spring:bean>

and inside the flow do:

<component>
    <spring-object bean="component" />
</component>

From the property element description in the XSD: 从XSD中的property元素描述:

Sets a Mule property. 设置一个Mule属性。 This is a name/value pair that can be set on components, services, etc., and which provide a generic way of configuring the system. 这是一个名称/值对,可以在组件,服务等上设置,并提供配置系统的通用方法。 Typically, you shouldn't need to use a generic property like this, since almost all functionality is exposed via dedicated elements. 通常,您不需要使用这样的通用属性,因为几乎所有功能都是通过专用元素公开的。 However, it can be useful in configuring obscure or overlooked options and in configuring transports from the generic endpoint elements. 但是,它在配置晦涩或被忽视的选项以及配置来自通用端点元素的传输时很有用。

This means it's not intended for what you are trying to use it. 这意味着它不适合您要使用的内容。 The appropriate way to set a property in your bean is as follows: 在bean中设置属性的适当方法如下:

<spring:bean id="component" name="component" class="com.threads.test.SpringObject" lazy-init="false">
    <spring:property name="someData" value="Information"/>
</spring:bean>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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