【发布时间】:2021-08-28 05:00:49
【问题描述】:
我正在尝试通过我的应用程序中的端点公开某些属性源中的所有属性。我可以使用 MutablePropertySources 来获取环境中可用的所有 propertySources,但我的问题是如何迭代 propertySource?
【问题讨论】:
标签: spring spring-boot properties
我正在尝试通过我的应用程序中的端点公开某些属性源中的所有属性。我可以使用 MutablePropertySources 来获取环境中可用的所有 propertySources,但我的问题是如何迭代 propertySource?
【问题讨论】:
标签: spring spring-boot properties
我想我已经找到了解决方案,您基本上需要使用 EnumrablePropertySource 而不是 propertySource 并使用它来获取名称(键)数组,然后使用它通过调用 env.getProperty(name) 来获取值
代码大概是这样的: EnumerablePropertySource propertySource=(EnumerablePropertySource) 可配置环境.getPropertySources().get(SOME_PROPERTYSOURCE_NAME); Arrays.stream(propertySource.getPropertyNames()).forEach(s->System.out.println(s+"="+configurableEnvironment.getProperty(s)));
【讨论】: