|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.health;
|
18 | 18 |
|
19 |
| -import java.util.LinkedHashMap; |
20 |
| -import java.util.Map; |
21 |
| - |
22 | 19 | import org.springframework.beans.factory.ObjectProvider;
|
23 | 20 | import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
|
24 |
| -import org.springframework.boot.actuate.health.CompositeHealthIndicatorFactory; |
25 | 21 | import org.springframework.boot.actuate.health.HealthAggregator;
|
26 | 22 | import org.springframework.boot.actuate.health.HealthEndpoint;
|
27 |
| -import org.springframework.boot.actuate.health.HealthIndicator; |
| 23 | +import org.springframework.boot.actuate.health.HealthIndicatorRegistry; |
28 | 24 | import org.springframework.boot.actuate.health.OrderedHealthAggregator;
|
29 |
| -import org.springframework.boot.actuate.health.ReactiveHealthIndicator; |
30 | 25 | import org.springframework.boot.actuate.health.StatusEndpoint;
|
31 | 26 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
32 | 27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
33 |
| -import org.springframework.context.ApplicationContext; |
34 | 28 | import org.springframework.context.annotation.Bean;
|
35 | 29 | import org.springframework.context.annotation.Configuration;
|
36 |
| -import org.springframework.util.ClassUtils; |
37 | 30 |
|
38 | 31 | /**
|
39 | 32 | * {@link EnableAutoConfiguration Auto-configuration} for {@link HealthEndpoint}.
|
40 | 33 | *
|
41 | 34 | * @author Andy Wilkinson
|
42 | 35 | * @author Stephane Nicoll
|
43 | 36 | * @author Phillip Webb
|
| 37 | + * @author Vedran Pavic |
44 | 38 | * @since 2.0.0
|
45 | 39 | */
|
46 | 40 | @Configuration
|
47 | 41 | public class HealthEndpointAutoConfiguration {
|
48 | 42 |
|
49 |
| - private final HealthIndicator healthIndicator; |
| 43 | + private final HealthAggregator healthAggregator; |
50 | 44 |
|
51 |
| - public HealthEndpointAutoConfiguration(ApplicationContext applicationContext, |
52 |
| - ObjectProvider<HealthAggregator> healthAggregator) { |
53 |
| - this.healthIndicator = getHealthIndicator(applicationContext, |
54 |
| - healthAggregator.getIfAvailable(OrderedHealthAggregator::new)); |
55 |
| - } |
| 45 | + private final HealthIndicatorRegistry healthIndicatorRegistry; |
56 | 46 |
|
57 |
| - private HealthIndicator getHealthIndicator(ApplicationContext applicationContext, |
58 |
| - HealthAggregator healthAggregator) { |
59 |
| - Map<String, HealthIndicator> indicators = new LinkedHashMap<>(); |
60 |
| - indicators.putAll(applicationContext.getBeansOfType(HealthIndicator.class)); |
61 |
| - if (ClassUtils.isPresent("reactor.core.publisher.Flux", null)) { |
62 |
| - new ReactiveHealthIndicators().get(applicationContext) |
63 |
| - .forEach(indicators::putIfAbsent); |
64 |
| - } |
65 |
| - CompositeHealthIndicatorFactory factory = new CompositeHealthIndicatorFactory(); |
66 |
| - return factory.createHealthIndicator(healthAggregator, indicators); |
| 47 | + public HealthEndpointAutoConfiguration(ObjectProvider<HealthAggregator> healthAggregator, |
| 48 | + ObjectProvider<HealthIndicatorRegistry> healthIndicatorRegistry) { |
| 49 | + this.healthAggregator = healthAggregator.getIfAvailable(OrderedHealthAggregator::new); |
| 50 | + this.healthIndicatorRegistry = healthIndicatorRegistry.getObject(); |
67 | 51 | }
|
68 | 52 |
|
69 | 53 | @Bean
|
70 | 54 | @ConditionalOnMissingBean
|
71 | 55 | @ConditionalOnEnabledEndpoint
|
72 | 56 | public HealthEndpoint healthEndpoint() {
|
73 |
| - return new HealthEndpoint(this.healthIndicator); |
| 57 | + return new HealthEndpoint(this.healthAggregator, this.healthIndicatorRegistry); |
74 | 58 | }
|
75 | 59 |
|
76 | 60 | @Bean
|
77 | 61 | @ConditionalOnMissingBean
|
78 | 62 | @ConditionalOnEnabledEndpoint
|
79 | 63 | public StatusEndpoint statusEndpoint() {
|
80 |
| - return new StatusEndpoint(this.healthIndicator); |
81 |
| - } |
82 |
| - |
83 |
| - private static class ReactiveHealthIndicators { |
84 |
| - |
85 |
| - public Map<String, HealthIndicator> get(ApplicationContext applicationContext) { |
86 |
| - Map<String, HealthIndicator> indicators = new LinkedHashMap<>(); |
87 |
| - applicationContext.getBeansOfType(ReactiveHealthIndicator.class) |
88 |
| - .forEach((name, indicator) -> indicators.put(name, adapt(indicator))); |
89 |
| - return indicators; |
90 |
| - } |
91 |
| - |
92 |
| - private HealthIndicator adapt(ReactiveHealthIndicator indicator) { |
93 |
| - return () -> indicator.health().block(); |
94 |
| - } |
95 |
| - |
| 64 | + return new StatusEndpoint(this.healthAggregator, this.healthIndicatorRegistry); |
96 | 65 | }
|
97 | 66 |
|
98 | 67 | }
|
0 commit comments