public static Map<String, Object> getAllProperties(ConfigurableEnvironment aEnv) { Map<String, Object> result = new HashMap<>(); aEnv.getPropertySources().forEach(ps -> addAll(result, getAllProperties(ps))); return result; }
EnvCopy(final ConfigurableEnvironment environment) { copy = new StandardEnvironment(); environment.getPropertySources().forEach(ps -> { final PropertySource<?> original = ps instanceof EncryptablePropertySource ? ((EncryptablePropertySource) ps).getDelegate() : ps; copy.getPropertySources().addLast(original); }); }
public static Map<String, String> getAllProperties(ConfigurableEnvironment aEnv) { Map<String, String> result = new HashMap<>(); aEnv.getPropertySources().forEach(ps -> { result.putAll(getAllProperties(ps)); }); return result; }
public static Map<String,Object> getAllProperties(ConfigurableEnvironment aEnv) { Map<String,Object> result = new HashMap<>(); aEnv.getPropertySources().forEach(ps -> addAll(result, getAllProperties(ps))); return result; }
public Map<String,Object> getAllProperties() { Map<String,Object> result = new HashMap<>(); environment.getPropertySources().forEach( ps -> addAll( result, getAllProperties( ps ) ) ); return result; }
protected static Map<String, Object> getAllProperties(ConfigurableEnvironment aEnv) { Map<String, Object> result = new HashMap<>(); aEnv.getPropertySources().forEach(ps -> addAll(result, getAllProperties(ps))); return result; }
public Map<String,Object> getAllProperties( ConfigurableEnvironment aEnv ) { Map<String,Object> result = new HashMap<>(); aEnv.getPropertySources().forEach(ps -> addAll(result, getAllProperties(ps))); return result; }
@Bean public Map<String,Map<String,String>> externalProperties(){ MutablePropertySources mutablePropertySources = environment.getPropertySources(); Map<String,Map<String,String>> result = Maps.newHashMap(); mutablePropertySources.forEach(mps -> { String pathName = mps.getName(); String keyName = null; if (pathName.contains(quartzConfigFileName)) { keyName = quartzConfigFileName; } else if(pathName.contains(dbConfigFileName)) { keyName = dbConfigFileName; } else if(pathName.contains(redisConfigFileName)){ keyName = redisConfigFileName; } if (Objects.nonNull(keyName)) { result.put(keyName,(Map<String, String>) mps.getSource()); } }); return result; }
public static void main(String[] args) { ConfigurableApplicationContext context = new SpringApplicationBuilder(ExtendPropertySourcesBootstrap.class) .web(WebApplicationType.NONE) // 非 Web 应用 .run(args); // 获取 Environment ConfigurableEnvironment environment = context.getEnvironment(); // 加载 META-INF/runtime.properties 配置文件 ResourcePropertySource propertySource = PropertySourceUtils.getResourcePropertySource("META-INF/runtime.properties"); // 追加至 PropertySources 顶端 environment.getPropertySources().addFirst(propertySource); // 读取 user.name 属性内容 System.out.println("从 Environment 读取属性 user.name = " + environment.getProperty("user.name")); System.out.println("Environment 所有 PropertySource : "); environment.getPropertySources().forEach(source -> { System.out.printf("\t %s\n", source); }); // 关闭上下文 context.close(); } }
EnvCopy(final ConfigurableEnvironment environment) { copy = new StandardEnvironment(); environment.getPropertySources().forEach(ps -> { final PropertySource<?> original = ps instanceof EncryptablePropertySource ? ((EncryptablePropertySource) ps).getDelegate() : ps; copy.getPropertySources().addLast(original); }); }
ConfigurableEnvironment ce = (ConfigurableEnvironment) o; MutablePropertySources cemps = ce.getPropertySources(); cemps.forEach(propSource -> { cemps.replace(propSource.getName(), new PropertySourceProxy(propSource)); });
env.getPropertySources().forEach(source -> { if (source instanceof EnumerablePropertySource) { final EnumerablePropertySource<?> eSource = (EnumerablePropertySource<?>) source;