Spring Boot执行器运行状况端点
我已经创建了一个PostgreSQL运行状况指示器,如下所示:
@Componentpublic 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();
        }
    }
}
在我的Application.java中,我正在扫描此软件包中的该组件:
@ComponentScan({"com.bp.health"})在我的application.properties中,我进行了以下设置:
endpoints.health.sensitive=falseendpoints.health.id=health
endpoints.health.enabled=true
当我点击{url} / health时,我看到:
{“状态”:“ DOWN”}
我需要怎么做才能显示自定义健康指标?
回答:
您需要进行身份验证才能查看所有详细信息。或者,您可以设置
management.security.enabled=falseendpoints.health.sensitive=false
查看未认证的完整内容
有关此的更多信息,请参见: 生产就绪监控
以上是 Spring Boot执行器运行状况端点 的全部内容, 来源链接: utcz.com/qa/397237.html

