@@ -204,28 +204,14 @@ public static void reload(){
204
204
private static void overloadFromSystemEnv () {
205
205
Map <String , String > sysEnv = new HashMap <>();
206
206
for (String key : props .keySet ()){
207
- String val = System .getenv (propertyNameToEnvVarName ( key ));
207
+ String val = System .getenv (key . replace ( "." , "_" ). replace ( "-" , "_" ). toUpperCase ( ));
208
208
if (!blank (val )){
209
209
sysEnv .put (key , val );
210
210
}
211
211
}
212
212
registerMap (sysEnv , "System.getenv()" );
213
213
}
214
214
215
- /**
216
- * Translates a property name to an environment variable name.
217
- * A typical Java property name uses lower case words punctuated by dots:
218
- * <code>server.port</code>. However, environment variables typically use upper case
219
- * characters and cannot have dots in a name. This method converts property names to environment variable names:
220
- * <code>server.port</code> is converted to <code>SERVER_PORT</code>
221
- * @param propName name of a Java property
222
- *
223
- * @return name of a property converted to system environment variable name.
224
- */
225
- public static String propertyNameToEnvVarName (String propName ) {
226
- return propName .replace ("." , "_" ).replace ("-" , "_" ).toUpperCase ();
227
- }
228
-
229
215
/**
230
216
* Will merge defined values into placeholders like ${placeholder}
231
217
*/
@@ -346,21 +332,18 @@ public static Property getAsProperty(String key) {
346
332
347
333
/**
348
334
* Returns property value for a key.
349
- * <br/>
350
- *
351
- * If this method does not find a property defined in the property files, it converts the property name to
352
- * environment variable name {@link #propertyNameToEnvVarName} and falls through
353
- * to a corresponding environment variable value.
335
+ * If the value is null, it will be sourced from the system environment
336
+ * variables.
354
337
*
355
- * @param propertyName name of a property.
356
- * @return value for this property , <code>null</code> if not found.
338
+ * @param key key of property.
339
+ * @return value for this key , <code>null</code> if not found.
357
340
*/
358
- public static String getProperty (String propertyName ) {
341
+ public static String getProperty (String key ) {
359
342
if (!isInited ()) {
360
343
init ();
361
344
}
362
- Property p = props .get (propertyName );
363
- return p == null ? System .getenv (propertyNameToEnvVarName ( propertyName ) ) : p .getValue ();
345
+ Property p = props .get (key );
346
+ return p == null ? System .getenv (key ) : p .getValue ();
364
347
}
365
348
366
349
0 commit comments