【问题标题】:Iterate over properties from a PropertySource Springboot迭代来自 PropertySource Spring Boot 的属性
【发布时间】:2021-08-28 05:00:49
【问题描述】:

我正在尝试通过我的应用程序中的端点公开某些属性源中的所有属性。我可以使用 MutablePropertySources 来获取环境中可用的所有 propertySources,但我的问题是如何迭代 propertySource?

【问题讨论】:

    标签: spring spring-boot properties


    【解决方案1】:

    我想我已经找到了解决方案,您基本上需要使用 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)));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-21
      • 2019-12-15
      • 2018-02-15
      • 2016-09-02
      • 1970-01-01
      • 2017-04-18
      • 1970-01-01
      • 2020-10-26
      相关资源
      最近更新 更多