不要为Spring Boot Actuator / health端点显示磁盘空间和数据库

时间:2017-07-21 20:42:54

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

我正在运行Spring Boot v1.5.2.RELEASE。

当我curl localhost:8080/health时,我得到:

{
    "status": "UP",
    "test": {
        "status": "UNKNOWN",
        "hello": "test123"
    },
    "diskSpace": {
        "status": "UP",
        "total": 999234207744,
        "free": 806942392320,
        "threshold": 10485760
    },
    "db": {
        "status": "UP",
        "database": "MySQL",
        "hello": 1
    }
}

以下是我的TestHealthIndicator.java代码:

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health.Builder;
import org.springframework.stereotype.Component;

@Component
public class TestHealthIndicator extends AbstractHealthIndicator {

    @Override
    protected void doHealthCheck(Builder builder) throws Exception {
        builder.withDetail("hello", "test123");
    }
}

我在pom.xml

中也有这个
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

问题:如果没有db和diskspace信息,如何让/health返回类似下面的内容?

{
    "status": "UP",
    "test": {
        "status": "UNKNOWN",
        "hello": "test123"
    }
}

1 个答案:

答案 0 :(得分:4)

根据docs,您可以使用以下属性禁用所有自定义HealthIndicator bean:

management.health.defaults.enabled=false