title: Is there a way to provide default values for env variables in a properties file with apache-commons?
body: <p>I'm using <code>org.apache.commons:commons-configuration2:2.5</code> to read config parameters from a config file. In my <code>application.properties</code>, I want to specify default values for environment variables in case one of these has not been set, e.g. like so (similar as with Spring):</p>
  
  <pre><code>idp.username=${env:IDP_USERNAME:defaultUsername}
  </code></pre>
  
  <p>However, while setting the env variable works fine, specifying a default value like this is not working. Unfortunately, I can't find anything related to this in the <code>commons-configuration2</code> documentation. Is this possible without explicitly checking for a missing value in the Java code? Does Spring Boot use a certain lib for this that I could also use? I don't want to bloat up my simple app with the Spring framework only to have this kind of configuration.</p>
  
  <p>Simplified code example I'm currently using (here, I obviously could check each property I retrieve and replace it with a default, but I'd like to avoid this and handle it directly in the config file):</p>
  
  <pre class="lang-java prettyprint-override"><code>private void loadConfigFile() {
          logger.info("Attempting to load `application.properties`...");
          Configurations configBuilder = new Configurations();
          try {
              Configuration props = configBuilder.properties(new File("application.properties"));
  
              // application config
              this.conf = new Config();
              this.conf.setAPIEndpoint(props.getString("api.endpoint"));
              this.conf.setMaxConnections(props.getInt("api.maxConnections"));
              ...
  
              logger.info("Config successfully loaded!");
          } catch (Exception e) {
              logger.error("Could not load `application.properties`: {}", e.getMessage());
              System.exit(1);
          }
      }
  </code></pre>
  
  <p>Any suggestions?</p>