java - Spring Boot Actuator configprops端点不返回@Value注释的属性

标签 java spring-boot

我正在为我们的 IT 团队编写一个中央控制台,以显示从 Spring Boot Actuator 端点/configprops 检索到的 SOA 生态系统中运行的每个微服务的属性。我有 2 个问题

  1. 尽管文档说,@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/

    相关文章:

    java - 我可以在不提供 URL 中的端口的情况下访问我的 Spring Boot 应用程序吗?

    java - 构建健康指标 spring boot

    angular - 使用 Spring Boot 从服务器端重定向到 Angular 路由

    java - 我可以让 Tomcat 作为转储堆的服务运行吗?

    java - 玩家移动的 ActionListener 或 Action

    java - 通过编译时检查获取类的方法对象(在 Java 中)

    java - SpringBoot单元测试不使用Application类的@EnableAutoConfiguration注解

    java - java中锁定文件

    java - 如何避免阻塞 Java ServerSocket?

    java - @DataJpaTest 中的存储库初始化为 null