繁体   English   中英

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

[英]Changing spring boot actuator health end point to a custom end point

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

http://localhost:8080/actuator/health

http://localhost:8080/myapp/apphealth

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

是的,这是可能的。

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

该文件指出:

如果要将端点映射到不同的路径,可以使用 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

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

路径将是: 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

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


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

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

-- application.properties --
management.endpoints.web.base-path=/

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


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

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

-- application.properties --
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=test

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


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

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

-- application.properties --
management.server.port=8081

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

暂无
暂无

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

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