云淘

Generation

code to explanationSat, 18 Feb 2023

public static String get(String key){ if(environment == null){ try{ environment = ContextHelper.getApplicationContext().getEnvironment(); } catch (Exception e){ log.warn("无法获取Environment,参数配置可能不生效"); } } // 获取配置值 if(environment == null){ log.warn("无法获取上下文Environment,请在Spring初始化之后调用!"); return null; } String value = environment.getProperty(key); // 任何password相关的参数需解密 boolean isSensitiveConfig = key.contains(".password") || key.contains(".secret"); if(value != null && isSensitiveConfig){ value = Encryptor.decrypt(value); } return value; }

The get method first tries to get the Environment from ContextHelper. If the ContextHelper can not get the Environment, it will try to create a new environment by itself. Then return the value corresponding to the key in the environment. If it can not find the key, it will return null.

Questions about programming?Chat with your personal AI assistant