protected final void bindPropertiesWithOverrides ( final String propertyFile ) { checkNotNull ( propertyFile , "classpath resource property file must not be null" ) ; Properties properties = new Properties ( ) ; // load classpath resource properties InputStream inputStream = getClass ( ) . getResourceAsStream ( propertyFile ) ; if ( inputStream != null ) { try { properties . load ( inputStream ) ; } catch ( IOException e ) { // ignore } } // override with system properties properties . putAll ( System . getProperties ( ) ) ; // override with environment variables for ( Map . Entry < String , String > entry : System . getenv ( ) . entrySet ( ) ) { String reformattedKey = entry . getKey ( ) . replace ( ' ' , ' ' ) ; // only replace existing keys if ( properties . containsKey ( reformattedKey ) ) { properties . put ( reformattedKey , entry . getValue ( ) ) ; } } // bind merged properties bindProperties ( properties ) ; }
Bind properties from the specified classpath resource property file overriding those values with system properties and with environment variables after replacing key underscores _ by dots . .