我在我的应用程序中使用的是SpringBoot v1.5.3,我添加了执行器health、info和度量,它们使用可用的端点工作得很好。我需要获取我的应用程序的全局健康状态。
这是我的代码:
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())));
}
}不幸的是,我的代码返回空异常,因为我没有获得运行状态对象。有人知道怎么做吗。谢谢!
发布于 2020-10-30 19:14:06
private HealthEndpoint healthEndpoint;可能是空的?如何在组件中设置/注入?我没有看到任何构造函数会为它设置值。
发布于 2020-10-31 01:45:26
我认为下面的行给出了一个NPE,因为您没有注入HealthEndPoint的依赖项。
Health health = ((HealthIndicator) this.healthEndpoint).health();您是否可以尝试自动装配或为HealthEndPoint执行构造函数注入,并查看它是否有效。
https://stackoverflow.com/questions/64608311
复制相似问题