使用Mule中的Spring Expression Language从属性文件加载值

时间:2015-10-07 10:11:06

标签: java mule

我有一个属性文件,其中包含我要加载的路径值,以便在我的程序中使用。

我的XML

中有以下内容

<flow doc:name="Flow1" name="Flow1">
    <http:inbound-endpoint doc:description="This endpoint receives an HTTP message."
        doc:name="HTTP" exchange-pattern="request-response" host="localhost"
        port="8081" contentType="text/html" />
    <custom-transformer class="com.test.app.mule.ReadFile" doc:name="Java">
        <spring:property name="path" value="${key.path1}" />
    </custom-transformer>

以及我的java代码中的以下内容(从属性文件中加载指定路径中的文件)

public class ReadFile extends AbstractMessageTransformer {


    private String path;


    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    /**
     * loads the content of the file specified in the parameter
     * 
     * @param filename
     *            the name of the file
     * @return the content of the file
     * 
     * 
     */

    public String readFile(String filename, String filePath) {

        File file1 = new File(path, filePath);

这很好但是我想知道是否有任何方法可以修改我允许使用@value注释的内容

private @Value("${key.path1") String path;并摆脱了二传手和吸气鬼?

骡子在这样做时似乎不会很好。