简体   繁体   中英

Environment variables with wildfly not working

In my application launching I get some variables from env variables in app properties.

It works fine with spring boot container.

But when I launch the application with wildfly 10 System.getenv always return null. I set my env variables in run configuration in STS, also it doesn't work in openshift that run wildfly.

Here is sample of my code:

String showSql = System.getenv("SHOW_SQL");

if(value.contains(":")){
    int split = value.indexOf(":");
    List<String> s = new ArrayList<String>();
    s.add(value.substring(1, split)) ;
    s.add(value.substring(split+1, value.length()-1));
    // value.split(":");

    if(System.getenv(s.get(0)) != null){
        var = System.getenv(s.get(0));
    }else{
        var = s.get(1);
        var = var.replace(":", "");
    }                           
}else{
    value = value.replace("{", "");
    value = value.replaceAll("}", "");
    var = System.getenv(value);
}

Can any one help me?

You can set a property in Wildfly with the jboss-cli using the command /system-property=foo:add(value=bar) which you can get then from your application using System.getProperty (a reload in the meanwhile might be required). The property will be stored into the Wildfly configuration thus it will survive a reboot :)

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