首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何获得全球健康状态执行器springboot 1.5.3

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

Stack Overflow用户
提问于 2020-10-30 12:24:15
回答 2查看 449关注 0票数 0

我在我的应用程序中使用的是SpringBoot v1.5.3,我添加了执行器health、info和度量,它们使用可用的端点工作得很好。我需要获取我的应用程序的全局健康状态。

这是我的代码:

代码语言:javascript
复制
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())));
    }
}

不幸的是,我的代码返回空异常,因为我没有获得运行状态对象。有人知道怎么做吗。谢谢!

EN

回答 2

Stack Overflow用户

发布于 2020-10-30 19:14:06

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

票数 0
EN

Stack Overflow用户

发布于 2020-10-31 01:45:26

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

代码语言:javascript
复制
    Health health = ((HealthIndicator) this.healthEndpoint).health();

您是否可以尝试自动装配或为HealthEndPoint执行构造函数注入,并查看它是否有效。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64608311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档