Spring启动执行器健康端点

Spring启动执行器健康端点,spring,spring-boot,spring-boot-actuator,actuator,Spring,Spring Boot,Spring Boot Actuator,Actuator,我创建了一个PostgreSQL运行状况指示器,如下所示: @Component public class PostgresHealthIndicator extends AbstractHealthIndicator { @Autowired DataSource postgresDataSource; public DataSourceHealthIndicator dbHealthIndicator() { DataSourceHealthInd

我创建了一个PostgreSQL运行状况指示器,如下所示:

@Component
public class PostgresHealthIndicator extends AbstractHealthIndicator {

    @Autowired
    DataSource postgresDataSource;

    public DataSourceHealthIndicator dbHealthIndicator() {
        DataSourceHealthIndicator indicator = new DataSourceHealthIndicator(postgresDataSource);
        return indicator;
    }

    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        Health h = dbHealthIndicator().health();
        Status status = h.getStatus();
        if (status != null && "DOWN".equals(status.getCode())) {
            builder.down();
        } else {
            builder.up();
        }
    }
}
在my Application.java中,我正在扫描此包以查找此组件:

@ComponentScan({"com.bp.health"})
在我的application.properties中,我有以下设置:

endpoints.health.sensitive=false
endpoints.health.id=health
endpoints.health.enabled=true
当我点击{url}/health时,我看到:

{“状态”:“关闭”}


我需要做什么才能让自定义健康指示器显示出来?

为什么要这么做?该代码甚至没有编译,SpringBoot默认情况下已经检查了您的数据源。如果您只看到状态,那是因为您未通过身份验证,请查看此表以了解更多详细信息。

您需要通过身份验证才能查看所有详细信息。 或者你可以设置

management.security.enabled=false
endpoints.health.sensitive=false
查看未经身份验证的完整内容

有关这方面的更多信息,请参见: