如何获得全球健康状态执行器springboot 1.5.3



我在应用程序中使用SpringBoot v 1.5.3,并添加了执行器健康、信息和指标,它们使用可用的端点运行良好。我需要获取我的应用程序的全局运行状况

这是我的代码:

package com.test.health.indicator;

import java.util.Collections;
import org.springframework.boot.actuate.endpoint.HealthEndpoint;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;
import org.springframework.boot.actuate.health.Status;
@Component
public class healthContributorToInfo implements InfoContributor {
private HealthEndpoint healthEndpoint;


@Override
public void contribute(Info.Builder builder) {

Health health = ((HealthIndicator) this.healthEndpoint).health();
Status status = health.getStatus();

builder.withDetail("Health Indicator",
Collections.singletonMap("Global Satatus", Health.status(status.getCode())));
}
}

不幸的是,我的代码返回null异常,因为我没有得到健康状态对象。有人知道怎么做吗。非常感谢。

private HealthEndpoint healthEndpoint;可能为空?它是如何设置/注入组件的?我没有看到任何构造函数会为它设置值

我认为下一行给出了一个NPE,因为您没有注入HealthEndPoint的依赖项。

Health health = ((HealthIndicator) this.healthEndpoint).health();

你能尝试自动布线或为HealthEndPoint注入构造函数吗?看看这是否有效。

最新更新