gio10245
gio10245

Reputation: 37

Loading value from properties file using Spring Expression Language in Mule

I have a properties file that contains a path value that I want to load in for use within my program.

I have the following in my 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>

and the following in my java code (which loads a file from the specified path from the properties file)

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);

This works fine however I am wondering is there any way to modify what I have to allow for the use of the @value annotation

private @Value("${key.path1") String path; and get rid of the setters and getters?

Mule doesn't seem to play nice when doing so.

Upvotes: 0

Views: 1053

Answers (1)

Related Questions