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

Do not show diskspace and db for Spring Boot Actuator /health endpoint

我是运行 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>

问题:如何在没有数据库和磁盘空间信息的情况下将 /health 变为 return 之类的内容?

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

根据 docs,您可以使用以下 属性:

禁用所有自定义 HealthIndicator bean
management.health.defaults.enabled=false