@Autowired
Environment env;
@GetMapping("properties")
public Map<String, Object> allProperties() {
Map<String, Object> map = new HashMap<>();
map.put("activeProfiles", env.getActiveProfiles());
map.put("defaultProfiles", env.getDefaultProfiles());
MutablePropertySources sources = ((AbstractEnvironment) env).getPropertySources();
for (PropertySource<?> source : sources) {
if (source instanceof EnumerablePropertySource) {
EnumerablePropertySource propertySource = (EnumerablePropertySource) source;
for (String s : propertySource.getPropertyNames()) {
map.put(s, propertySource.getProperty(s));
}
}
}
return map;
}
参考: https://gist.github.com/sandor-nemeth/f6d2899b714e017266cb9cce66bc719d