将弹簧引导执行器运行状况端点更改为自定义端点

ACP*_*ACP 7 java spring-boot spring-boot-actuator

是否可以将弹簧靴执行器健康端点更改为自定义端点?像下面这样的东西。

http://localhost:8080/actuator/health

http://localhost:8080/myapp/apphealth

只想更改名称,而不是执行器/健康的响应。是否可以?

The*_*ger 11

是的,这是可能的。

文档的这一部分定义了如何自定义执行器端点的路径。

该文件指出:

如果要将端点映射到不同的路径,可以使用 management.endpoints.web.path-mapping 属性。

以下示例将 /actuator/health 重新映射到 /healthcheck:

应用程序属性。

management.endpoints.web.base-path=/

management.endpoints.web.path-mapping.health=healthcheck

所以,在你的情况下,你想要:

-- application.properties --
management.endpoints.web.base-path=/myapp
management.endpoints.web.path-mapping.health=apphealth
Run Code Online (Sandbox Code Playgroud)


Kee*_*asa 9

这里给出的答案,已经为这个问题提供了解决方案。但是,我在为不同目的定制执行器健康端点时遇到了困难,我想分享我的发现以帮助其他人。以下所有示例均适用于Spring Boot 2.x.

默认的执行器健康端点是http://localhost:8080/actuator/health


选项 1:更改/actuator/health为自定义路径,例如/actuator/test

将以下内容添加到您的application.properties文件中

-- application.properties --
management.endpoints.web.path-mapping.health=test
Run Code Online (Sandbox Code Playgroud)

路径将是:http://localhost:8080/actuator/test


选项 2:更改/actuator/health为自定义路径,例如/myapp/test

将以下内容添加到您的application.properties文件中

-- application.properties --
management.endpoints.web.base-path=/myapp
management.endpoints.web.path-mapping.health=test
Run Code Online (Sandbox Code Playgroud)

路径将是:http://localhost:8080/myapp/test


选项 3:更改/actuator/health为自定义路径,例如/health

将以下内容添加到您的application.properties文件中

-- application.properties --
management.endpoints.web.base-path=/
Run Code Online (Sandbox Code Playgroud)

路径是:http://localhost:8080/health


选项 4:更改/actuator/health为自定义路径,例如/test

将以下内容添加到您的application.properties文件中

-- application.properties --
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=test
Run Code Online (Sandbox Code Playgroud)

路径将是:http://localhost:8080/test


选项 5:将端口从更改8080为自定义端口,例如8081

将以下内容添加到您的application.properties文件中。主应用程序将在 Port 上运行8080

-- application.properties --
management.server.port=8081
Run Code Online (Sandbox Code Playgroud)

路径将是:http://localhost:8081/actuator/health