简体   繁体   中英

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

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?

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 ...
}

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

---}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM