弹簧致动器的活性和准备状态正在恢复 404

Nar*_*ard 5 java spring spring-boot kubernetes spring-boot-actuator

这是我在 application.yaml 中的配置:

management:
  endpoint:
    health:
      show-details: "ALWAYS"
      probes:
        enabled: true
  endpoints:
    enabled-by-default: true
    web:
      exposure:
        include: metrics, health, caches, restart
Run Code Online (Sandbox Code Playgroud)

根据文档,这应该足以为 Spring 应用程序启用活性和就绪性探测。但端点(/actuator/health/liveness/actuator/health/readiness)仍然返回 404。我在配置中尝试了多种组合,但没有任何效果。你能告诉我该怎么办吗?

S.T*_*nov 9

我对这个问题进行了更深入的研究,因为我发现它是spring-boot-actuator. 根据我的研究,我发现此功能已在livenessreadiness中引入,spring-boot:2.3.0因此如果您使用的是旧版本,这可能是您在执行GET /actuator/health/readiness.

如果您将spring-boot版本升级到 >= 2.3.0,您可以通过添加以下内容来启用活性和就绪性探测器:

management:
  health:
    probes:
      enabled: true
Run Code Online (Sandbox Code Playgroud)

到您的application.yaml文件。这样做之后你应该能够

GET /actuator/health

{
    "status": "UP",
    "groups": [
        "liveness",
        "readiness"
    ]
}
Run Code Online (Sandbox Code Playgroud)

但是,对于 spring-boot 版本 >= 2.3.2,建议通过在 application.yaml 中使用以下内容来启用探测器

management:
  endpoint:
    health:
      probes:
        enabled: true 
Run Code Online (Sandbox Code Playgroud)

这样做的原因是一个错误,您可以在此处阅读更多信息

额外提示:如果您的spring-boot版本 >= 2.3.0,您已经相应地配置了您的 application.yaml 文件,并且当您的 application.yaml 文件没有被 Spring Context 拾取的可能性很小时,您仍然会收到404GET /actuator/health/liveness。您可以通过更改应用程序的端口来检查是否是这种情况

server:
  port: 8081
Run Code Online (Sandbox Code Playgroud)

如果您的应用程序没有在不同的端口上启动,则可以肯定地说您的任何配置都没有发生。我的 IDE 遇到过一两次这个问题。


小智 4

如果您使用 spring 2.3.2 或更高版本,请添加以下属性:

management.endpoint.health.probes.enabled=true
management.health.livenessState.enabled=true
management.health.readinessState.enabled=true
Run Code Online (Sandbox Code Playgroud)

  • 这个``management.endpoint.health.probes.enabled=true```单独启用了活性和就绪端点。您不需要单独的活动和就绪配置 (4认同)