How read properties from mule-app.properties in standalone deploy?

3k views Asked by At

In my mule application I defined some properties in mule-app.properties file, so I can change it "on the fly" on CloudHub. Deploying on CloudHub all is right, and to get the properties on java class I used: System.getProperty("propertyName").

Now my problem is that deploying the application on mule standalone, when It tries to use a property in a java class it returns null even if on xml file I can use properties with the usual ${propertyName}.

Is there any other way to access these properties from a java class?

2

There are 2 answers

2
Ryan Carter On BEST ANSWER

Cloudhub properties are set using System Properties, thats why you can access them via System.getProperty().

mule-app.properties is special as this properties file automatically gets loaded into the Mule registry so you could access it via the Mule Context. But it would be better to inject them into you Java class from your Mule config:

<bean class="YourJavaClass">
  <property name="myVar" value="${the.key}">
</bean>

public class YourJavaClass{
   String myVar ...
}
0
Anirban Sen Chowdhary On

An alternate solution is :

put your values in mule-app.properties:

poll.time=1000

Then in your Java class using Spring annotation to inject the value into a Java variable.

import org.springframework.beans.factory.annotation.Value;
public class Test{

    @Value("${poll.time}")
    String pollTime;

    public String getToken(String id) {

System.out.println("Poll Time"+pollTime);
}

---}