Created
November 9, 2017 00:44
-
-
Save sdhjl2000/062c4e63efe2560147063074f5fe9765 to your computer and use it in GitHub Desktop.
fetchAllProperties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Properties fetchAllProperties() { | |
final Properties properties = new Properties(); | |
for (Iterator it = ((AbstractEnvironment) environment).getPropertySources().iterator(); it.hasNext(); ) { | |
PropertySource propertySource = (PropertySource) it.next(); | |
if (propertySource instanceof EnumerablePropertySource) { | |
for (String key : ((EnumerablePropertySource) propertySource).getPropertyNames()) { | |
properties.put(key, propertySource.getProperty(key)); | |
} | |
} | |
if (propertySource instanceof PropertiesPropertySource) { | |
properties.putAll(((MapPropertySource) propertySource).getSource()); | |
} | |
if (propertySource instanceof CompositePropertySource) { | |
properties.putAll(getPropertiesInCompositePropertySource((CompositePropertySource) propertySource)); | |
} | |
} | |
return properties; | |
} | |
private Properties getPropertiesInCompositePropertySource(CompositePropertySource compositePropertySource) { | |
final Properties properties = new Properties(); | |
compositePropertySource.getPropertySources().forEach(propertySource -> { | |
if (propertySource instanceof EnumerablePropertySource) { | |
for (String key : ((EnumerablePropertySource) propertySource).getPropertyNames()) { | |
properties.put(key, propertySource.getProperty(key)); | |
} | |
} | |
if (propertySource instanceof MapPropertySource) { | |
properties.putAll(((MapPropertySource) propertySource).getSource()); | |
} | |
if (propertySource instanceof CompositePropertySource) | |
properties.putAll(getPropertiesInCompositePropertySource((CompositePropertySource) propertySource)); | |
}); | |
return properties; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment