当我从Spring Boot应用程序访问/ health端点时,它返回状态UP:
{
"status": "UP"
}
但我想自定义我的状态:
{
"status": "success"
}
如何自定义状态?
答案 0 :(得分:9)
创建新的运行状况构建器状态并将其返回。
@JsonProperty("status")
public String getCode() {
return this.code;
}
如果实施HealthIndicator
@Component
public class HealthChecker implements HealthIndicator {
@Override
public Health health() {
// Do checks ..
// if no issues
return Health.status("success").build();
}
}
如果扩展AbstractHealthIndicator
@Component
public class HealthIndicator extends AbstractHealthIndicator {
@Override
protected void doHealthCheck(Builder builder) throws Exception {
builder.status("success").build();
}
}
严重性顺序
要使其发挥作用,您必须通过将UP
替换为success
或在UP
之前移动
application.properties
management.health.status.order=DOWN, OUT_OF_SERVICE, UNKNOWN, success
或
management.health.status.order=DOWN, OUT_OF_SERVICE, UNKNOWN, success, UP