From 8fdc6f0898b4c1638fe4048e683f84a7ee81ab6c Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Thu, 7 Mar 2019 16:17:26 -0500 Subject: [PATCH] Fix health check handler so it is compatible with boot 2.2.0 --- .../eureka/EurekaHealthCheckHandler.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandler.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandler.java index 488fec383..026eab5a1 100644 --- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandler.java +++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandler.java @@ -25,8 +25,10 @@ import com.netflix.appinfo.InstanceInfo; import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.actuate.health.CompositeHealthIndicator; +import org.springframework.boot.actuate.health.DefaultHealthIndicatorRegistry; import org.springframework.boot.actuate.health.HealthAggregator; import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.boot.actuate.health.HealthIndicatorRegistryFactory; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.client.discovery.health.DiscoveryCompositeHealthIndicator; import org.springframework.context.ApplicationContext; @@ -59,13 +61,20 @@ public class EurekaHealthCheckHandler } }; - private final CompositeHealthIndicator healthIndicator; + private CompositeHealthIndicator healthIndicator; private ApplicationContext applicationContext; + private HealthIndicatorRegistryFactory healthIndicatorRegistryFactory; + + private HealthAggregator healthAggregator; + public EurekaHealthCheckHandler(HealthAggregator healthAggregator) { Assert.notNull(healthAggregator, "HealthAggregator must not be null"); - this.healthIndicator = new CompositeHealthIndicator(healthAggregator); + this.healthAggregator = healthAggregator; + this.healthIndicatorRegistryFactory = new HealthIndicatorRegistryFactory(); + this.healthIndicator = new CompositeHealthIndicator(this.healthAggregator, + new DefaultHealthIndicatorRegistry()); } @Override @@ -78,6 +87,7 @@ public class EurekaHealthCheckHandler public void afterPropertiesSet() throws Exception { final Map healthIndicators = applicationContext .getBeansOfType(HealthIndicator.class); + Map finalHealthIndicators = new HashMap<>(); for (Map.Entry entry : healthIndicators.entrySet()) { @@ -89,16 +99,18 @@ public class EurekaHealthCheckHandler for (DiscoveryCompositeHealthIndicator.Holder holder : indicator .getHealthIndicators()) { if (!(holder.getDelegate() instanceof EurekaHealthIndicator)) { - healthIndicator.addHealthIndicator(holder.getDelegate().getName(), - holder); + finalHealthIndicators.put(holder.getDelegate().getName(), holder); } } } else { - healthIndicator.addHealthIndicator(entry.getKey(), entry.getValue()); + finalHealthIndicators.put(entry.getKey(), entry.getValue()); } } + this.healthIndicator = new CompositeHealthIndicator(healthAggregator, + healthIndicatorRegistryFactory + .createHealthIndicatorRegistry(finalHealthIndicators)); } @Override