首页 > 解决方案 > 如何启用在自定义启动器/库中设置的执行器端点?

问题描述

我有自定义启动器应用程序(库),它具有执行器和普罗米修斯依赖项

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <version>1.5.2</version>
</dependency>

在 application.properties

management.endpoints.web.exposure.include=health, info, metrics, prometheus

我在我的其他应用程序中使用这个启动器,我还想从启动器传递端点的这个展示。Actuator 和 Prometheus 依赖项在应用程序中有效,但在 starter 中不显示选定的端点。Ofc 我也可以management.endpoints.web.exposure.include=health, info, metrics, prometheus在我的应用程序中添加行,但是对于使用此启动器的多个应用程序,我想一劳永逸地传递它,并仅在需要时在启动器中更改端点。

你知道如何在我的应用程序中公开那些在启动器中设置的端点吗?

Spring Boot v2.3.2 / Maven 3.6.3

标签: spring-bootendpointactuator

解决方案


当您启动应用程序时,您可以将其作为命令行参数或作为 ENV vars 传递给您的 jar。

这样,您可以在需要时将其传递给所需的应用程序,而无需更新 application.properties。

它还将防止在不需要时暴露执行器端点,因为执行器端点会显示有关应用程序的敏感信息。

例如。java -Dmanagement.endpoints.web.exposure.include=health, info, metrics, prometheus -jar myapp.jar


推荐阅读