我有一个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/创建此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());
}