【问题标题】:Spring Boot custom endpoint health checkSpring Boot 自定义端点健康检查
【发布时间】:2021-10-15 00:58:31
【问题描述】:

我想创建一个自定义端点,它会提供一些自定义信息。我知道有两种方法可以实现:HealthIndicator 和@Endpoint。 但是我想把我的端点放在另一个路径而不是默认的 /health/xxx 下,此外,从默认 /health 端点返回的原始健康信息也包含在我的自定义端点中。这种特殊情况我该怎么办?欣赏它。

【问题讨论】:

  • 为什么不使用@RestController 来实现自己的端点?您需要的自定义数据检索将来自HealthIndicator 接口实现。
  • /actuator/ 端点一旦包含就应该在那里,或者您只想将 /actuator/health 重定向到 /health?
  • @Ferimi-4 谢谢。你的意思是我点击 /actuator/health 并手动检索它的响应?
  • @BookOfZeus 谢谢。我的意思是我想创建一个像 /actuator/myCustomHealth 这样的新端点,而不是将它直接放在 /actuator/health/myCustomHealth 这样的默认 /health 路径下。但我还需要在我的新端点中包含从默认 /actuator/health 返回的所有数据

标签: spring-boot spring-boot-actuator health-check


【解决方案1】:

你可以重写application.properties中的url路径。

曾经,我需要将健康端点设置为 localhost:8080/rest/status 而不是 localhost:8080/actuator/health

为此,我在 application.properties 文件中添加了这两个设置,这对我有用。

# Change actuator -> rest
management.endpoints.web.base-path=/rest/
# Change health -> status
management.endpoints.web.path-mapping.health=status

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 1970-01-01
    • 2020-11-16
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    相关资源
    最近更新 更多