我正在为我们的 IT 团队编写一个中央控制台,以显示从 Spring Boot Actuator 端点/configprops 检索到的 SOA 生态系统中运行的每个微服务的属性。我有 2 个问题
- 尽管文档说,@Value 注释的属性似乎不会返回
63.7 Discover built-in options for external properties .... The definitive list comes from searching the source code for @ConfigurationProperties and @Value annotations, as well as the occasional use of RelaxedEnvironment
查看 ConfigurationPropertiesReportEndpoint.java,看起来它只搜索 @ConfigurationProperties 注释的类:
beans.putAll(context.getBeansWithAnnotation(ConfigurationProperties.class));
- 有没有一种简单的方法可以确定从何处解析出最终的属性值?例如:该属性是否通过环境变量被覆盖?或者,它来自 git 存储库吗?
最佳答案
第 63.7 节试图说明发现所有属性的唯一确定方法(因为它们可以通过多种方式绑定(bind))是搜索源代码。我们尝试尽可能使用@ConfigurationProperties,以便它们可以被IDE发现并被执行器公开。不幸的是,我们没有办法检测和公开报告中的每个属性。
目前还没有明确的方法来判断属性(property)的来源。您也许可以从 ConfigurableEnvironment
查看 getPropertySources()
。这将允许您迭代 PropertySource
项,然后您可以检查它们是否是 EnumerablePropertySource
并获取值。每个PropertySource
都有一个名称
,它可能会提供有关添加它的内容的线索。
关于java - Spring Boot Actuator configprops端点不返回@Value注释的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29991046/