定制弹簧靴执行器健康状态

时间:2017-02-17 12:43:28

标签: java spring spring-boot

当我从Spring Boot应用程序访问/ health端点时,它返回状态UP:

{
  "status": "UP"
}

但我想自定义我的状态:

{
  "status": "success"
}

如何自定义状态?

1 个答案:

答案 0 :(得分:9)

创建新的运行状况构建器状态并将其返回。

Status

@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