我正在运行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"
}
}
答案 0 :(得分:4)
根据docs,您可以使用以下属性禁用所有自定义HealthIndicator
bean:
management.health.defaults.enabled=false