繁体   English   中英

从 PropertySource Springboot 迭代属性

[英]Iterate over properties from a PropertySource Springboot

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

我想我已经找到了解决方案,您基本上需要使用 EnumrablePropertySource 而不是 propertySource 并使用它来获取名称(键)数组,然后使用它通过调用 env.getProperty(name) 来获取值

代码将是这样的: EnumerablePropertySource propertySource=(EnumerablePropertySource)izableEnvironment.getPropertySources().get(SOME_PROPERTYSOURCE_NAME); Arrays.stream(propertySource.getPropertyNames()).forEach(s->System.out.println(s+"="+configurableEnvironment.getProperty(s)));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM