是否可以将Spring Boot Actuator的健康端点更改为自定义端点?像下面这样:
http://localhost:8080/actuator/health
改为
http://localhost:8080/myapp/apphealth
只需更改名称而不更改actuator/health响应,是否可能实现?
是否可以将Spring Boot Actuator的健康端点更改为自定义端点?像下面这样:
http://localhost:8080/actuator/health
改为
http://localhost:8080/myapp/apphealth
只需更改名称而不更改actuator/health响应,是否可能实现?
是的,这是可能的。
如何自定义您的执行器端点路径在文档的这个部分中有定义。
文档说明:
如果您想将端点映射到不同的路径,则可以使用management.endpoints.web.path-mapping属性。
以下示例将/actuator/health重新映射为/healthcheck:
application.properties.
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
选项1:将/actuator/health
更改为自定义路径,例如/actuator/test
将以下内容添加到您的application.properties
文件中
-- application.properties --
management.endpoints.web.path-mapping.health=test
选项2:将/actuator/health
更改为自定义路径,例如/myapp/test
在您的application.properties
文件中添加以下内容
-- application.properties --
management.endpoints.web.base-path=/myapp
management.endpoints.web.path-mapping.health=test
/actuator/health
更改为像/health
这样的自定义路径application.properties
文件中添加以下内容。-- application.properties --
management.endpoints.web.base-path=/
/actuator/health
更改为自定义路径,例如/test
请在您的application.properties
文件中添加以下内容。-- application.properties --
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=test
选项5:将端口从8080
更改为自定义端口,如8081
将以下内容添加到您的application.properties
文件中。主应用程序将在端口8080
上运行。
-- application.properties --
management.server.port=8081