【问题标题】:Loading value from properties file using Spring Expression Language in Mule在 Mule 中使用 Spring 表达式语言从属性文件中加载值
【发布时间】:2015-10-07 10:11:05
【问题描述】:

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

我的 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; 并摆脱 setter 和 getter?

骡子这样做似乎不太好。

【问题讨论】:

    标签: java mule


    【解决方案1】:

    【讨论】:

    • 在春天?这非常模糊,没有任何链接提供有关此问题的帮助。
    • 您尝试做的是通过注释访问属性。我知道的方法是在 Mule 上配置上下文占位符,然后通过 @Value 注入属性。我会在这里找到一个示例。
    猜你喜欢
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多