Remove autowired injection of HealthIndicators into HealthEndpoint
Moved into EndpointAutoConfiguration
This commit is contained in:
parent
7ab78d1d0f
commit
fef998f914
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
@ -36,6 +37,7 @@ import org.springframework.boot.actuate.endpoint.RequestMappingEndpoint;
|
|||
import org.springframework.boot.actuate.endpoint.ShutdownEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.TraceEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.VanillaPublicMetrics;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.actuate.metrics.reader.MetricReader;
|
||||
import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository;
|
||||
import org.springframework.boot.actuate.trace.InMemoryTraceRepository;
|
||||
|
@ -59,7 +61,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
|
|||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for common management
|
||||
* {@link Endpoint}s.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @author Greg Turnquist
|
||||
|
@ -71,6 +73,9 @@ public class EndpointAutoConfiguration {
|
|||
@Autowired
|
||||
private InfoPropertiesConfiguration properties;
|
||||
|
||||
@Autowired(required = false)
|
||||
Map<String, HealthIndicator<? extends Object>> healthIndicators = new HashMap<String, HealthIndicator<? extends Object>>();
|
||||
|
||||
@Autowired(required = false)
|
||||
private MetricReader metricRepository = new InMemoryMetricRepository();
|
||||
|
||||
|
@ -92,7 +97,7 @@ public class EndpointAutoConfiguration {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public HealthEndpoint healthEndpoint() {
|
||||
return new HealthEndpoint();
|
||||
return new HealthEndpoint(this.healthIndicators);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.springframework.boot.actuate.health.RedisHealthIndicator;
|
|||
import org.springframework.boot.actuate.health.SimpleDataSourceHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.VanillaHealthIndicator;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
|
@ -45,11 +46,12 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for {@link HealthIndicator}s.
|
||||
*
|
||||
*
|
||||
* @author Christian Dupuis
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureBefore({ EndpointAutoConfiguration.class })
|
||||
@AutoConfigureAfter({ DataSourceAutoConfiguration.class, MongoAutoConfiguration.class,
|
||||
MongoDataAutoConfiguration.class, RedisAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class })
|
||||
|
|
|
@ -20,27 +20,28 @@ import java.util.LinkedHashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link Endpoint} to expose application health.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Christian Dupuis
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "endpoints.health", ignoreUnknownFields = false)
|
||||
public class HealthEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
|
||||
@Autowired(required = false)
|
||||
private Map<String, HealthIndicator<? extends Object>> healthIndicators;
|
||||
private final Map<String, HealthIndicator<? extends Object>> healthIndicators;
|
||||
|
||||
/**
|
||||
* Create a new {@link HealthIndicator} instance.
|
||||
*/
|
||||
public HealthEndpoint() {
|
||||
public HealthEndpoint(Map<String, HealthIndicator<? extends Object>> healthIndicators) {
|
||||
super("health", false, true);
|
||||
Assert.notNull(healthIndicators, "HealthIndicator must not be null");
|
||||
this.healthIndicators = healthIndicators;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@ import static org.junit.Assert.assertThat;
|
|||
|
||||
/**
|
||||
* Tests for {@link HealthEndpoint}.
|
||||
*
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class HealthEndpointTests extends AbstractEndpointTests<HealthEndpoint> {
|
||||
|
@ -51,8 +51,8 @@ public class HealthEndpointTests extends AbstractEndpointTests<HealthEndpoint> {
|
|||
public static class Config {
|
||||
|
||||
@Bean
|
||||
public HealthEndpoint endpoint() {
|
||||
return new HealthEndpoint();
|
||||
public HealthEndpoint endpoint(Map<String, HealthIndicator<?>> healthIndicators) {
|
||||
return new HealthEndpoint(healthIndicators);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
Loading…
Reference in New Issue