提问者:小点点

从默认 /actuator/healthendpoint排除邮件健康指示器?


我有一个Spring Boot应用程序,它使用执行器来具有/执行器/健康endpoint。我最近将spring-boot-starter-mail添加到应用程序中,它会自动为邮件服务器添加一个健康指示器,因此如果邮件服务器关闭,/执行器/健康将报告DOWN。

我想从/执行器/健康本身中删除该健康指示器,并有另一个endpoint/执行器/健康/邮件来获取完整状态。

我知道我可以通过添加以下属性来创建额外的endpoint:

management.endpoint.health.group.mail.include=mail

但是如何从默认endpoint中删除mail

我尝试使用management.health. mail.启用=false,但是我不能在/执行器/健康/邮件endpoint中使用它了。


共1个答案

匿名用户

这应该起作用:

1/创建此Healthendpoint扩展类:

public class HealthEndpointCustomExtension extends HealthEndpointWebExtension {

    public HealthEndpointCustomExtension(HealthContributorRegistry registry, HealthEndpointGroups groups, Duration slowIndicatorLoggingThreshold) {
        super(registry, groups, slowIndicatorLoggingThreshold);
    }

    @Override
    protected HealthComponent aggregateContributions(ApiVersion apiVersion, Map<String, HealthComponent> contributions, StatusAggregator statusAggregator, boolean showComponents, Set<String> groupNames) {
        Map<String, HealthComponent> newContributions = new HashMap<>(contributions);
        newContributions.remove("mail");
        return super.aggregateContributions(apiVersion, newContributions, statusAggregator, showComponents,  groupNames);
    }

聚合贡献方法,顾名思义,对每个健康贡献者进行聚合。通过覆盖此方法,您可以从聚合结果中删除“邮件”贡献者。

2/在配置类中声明您的自定义组件:

    @Bean
    HealthEndpointWebExtension healthEndpointWebExtension(HealthContributorRegistry healthContributorRegistry, HealthEndpointGroups groups, HealthEndpointProperties properties) {
        return new HealthEndpointCustomExtension(healthContributorRegistry, groups, properties.getLogging().getSlowIndicatorThreshold());
    }

相关问题