获取spring中所需信息
@Test
public void setUp(ApplicationContext applicationContext) throws Exception {
Environment environment = applicationContext.getEnvironment();
StandardEnvironment standardEnvironment= (StandardEnvironment) environment;
Map<String, Map<String, String>> map = new HashMap<>(8);
MutablePropertySources propertySources = standardEnvironment.getPropertySources();
PropertySource<?> propertySource = propertySources.get("applicationConfig: [classpath:/application.yml]");
Object source1 = propertySource.getSource();
Map<String,String>map1= (Map<String, String>) source1;
log.info(String.valueOf(map1.get("butler.config.name"))+"=========butler.config.name");
Iterator<PropertySource<?>> iterator = standardEnvironment.getPropertySources().iterator();
while (iterator.hasNext()) {
PropertySource<?> source = iterator.next();
Map<String, String> m = new HashMap<>(128);
String name = source.getName();
Object o = source.getSource();
if (o instanceof Map) {
for (Map.Entry<String, Object> entry : ((Map<String, Object>) o).entrySet()) {
String key = entry.getKey();
m.put(key, standardEnvironment.getProperty(key));
}
}
map.put(name, m);
}
log.info("{}",map);
}
修改spring环境中的信息