【问题标题】:Changing spring boot actuator health end point to a custom end point将 spring boot 执行器健康端点更改为自定义端点
【发布时间】:2019-03-10 07:41:39
【问题描述】:

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

http://localhost:8080/actuator/health

http://localhost:8080/myapp/apphealth

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

【问题讨论】:

标签: java spring-boot spring-boot-actuator


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    是的,有可能。

    如何自定义执行器端点的路径在文档的this 部分中定义。

    文档说明:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多