1

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?

Simon
  • 35
  • 1
  • 5

2 Answers2

4

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 ...
}
Ryan Carter
  • 11,441
  • 2
  • 20
  • 27
  • So deploying on mule standalone mule-app.properties it's not possible find them on System? And there is no way to set them there?? In Mule Context where are loaded? And can I ask you why it is not reccomended to use Mule Context? – Simon Dec 11 '14 at 13:47
  • 1
    You can set system properties via : -D-M-Dsome.key=value. see http://www.mulesoft.org/documentation/display/current/Configuring+Properties The problem with Mule context is just that you are are coupling your component to Mule internals. – Ryan Carter Dec 11 '14 at 16:41
1

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

---}
Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81