spring boot 获取所有属性
程序员文章站
2024-02-13 23:05:10
...
@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
上一篇: 浙大_数据结构_1:最大子列和
下一篇: iOS 定位说明