首页 > 解决方案 > springboot 2.3.0 actuator liveness/readiness check 返回错误响应

问题描述

我正在尝试使用 spring boot 2.3.0 在本地测试活跃度/准备情况。当我公开 API 时,它确实返回正确的状态,但不是正确的响应。基于https://spring.io/blog/2020/03/25/liveness-and-readiness-probes-with-spring-boot,当我公开时,我期待组件、磁盘空间等/actuator/health,但我得到:

{
    "status": "UP",
    "groups": [
        "liveness",
        "readiness"
    ]
}

我很确定我的 pom.xml 是正确的,因为它返回了正确的状态。我认为这与配置有关。这是我的本地配置设置(application.properties):

spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://myurl.net;database
spring.datasource.username=username
spring.datasource.password=password

management.health.probes.enabled=true
management.endpoint.health.group.readiness.include=readinessProbe,db

我错过了什么吗?即使我调用 /actuator/health/liveness,我得到的只是

{
    "status": "UP"
}

“状态”确实显示了正确的值(UP 或 DOWN),但缺少组件。

标签: javaspring-bootspring-boot-actuator

解决方案


健康端点公开的信息取决于management.endpoint.health.show-detailsmanagement.endpoint.health.show-components属性,可以使用以下值之一进行配置neverwhen-authorized, always。默认值为never

因此,如果您将值设置management.endpoint.health.show-componentsalways它应该显示您的期望。

有关更多详细信息,请参阅此处的文档


推荐阅读