diff --git a/spring-boot-actuator/pom.xml b/spring-boot-actuator/pom.xml index 1f3579a2ff..82137d735b 100644 --- a/spring-boot-actuator/pom.xml +++ b/spring-boot-actuator/pom.xml @@ -88,6 +88,10 @@ spring-test test + + org.hsqldb + hsqldb + ${project.groupId} spring-boot diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java index f0c762369e..e46645b434 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java @@ -20,6 +20,8 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; +import javax.sql.DataSource; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.actuate.endpoint.AutoConfigurationReportEndpoint; @@ -35,6 +37,7 @@ 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.health.SimpleHealthIndicator; import org.springframework.boot.actuate.health.VanillaHealthIndicator; import org.springframework.boot.actuate.metrics.InMemoryMetricRepository; import org.springframework.boot.actuate.metrics.MetricRepository; @@ -45,6 +48,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.boot.bind.PropertiesConfigurationFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -67,7 +71,10 @@ import org.springframework.http.MediaType; public class EndpointAutoConfiguration { @Autowired(required = false) - private HealthIndicator healthIndicator = new VanillaHealthIndicator(); + private HealthIndicator healthIndicator; + + @Autowired(required = false) + private DataSource dataSource; @Autowired private InfoPropertiesConfiguration properties; @@ -90,6 +97,16 @@ public class EndpointAutoConfiguration { @Bean @ConditionalOnMissingBean public HealthEndpoint healthEndpoint() { + if (this.healthIndicator == null) { + if (this.dataSource == null) { + this.healthIndicator = new VanillaHealthIndicator(); + } + else { + SimpleHealthIndicator healthIndicator = new SimpleHealthIndicator(); + healthIndicator.setDataSource(this.dataSource); + this.healthIndicator = healthIndicator; + } + } return new HealthEndpoint(this.healthIndicator); } @@ -134,7 +151,7 @@ public class EndpointAutoConfiguration { @Bean @ConditionalOnBean(AutoConfigurationReport.class) - @ConditionalOnMissingBean + @ConditionalOnMissingBean(search = SearchStrategy.CURRENT) public AutoConfigurationReportEndpoint autoConfigurationAuditEndpoint() { return new AutoConfigurationReportEndpoint(); } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHealthIndicator.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHealthIndicator.java index 6a19960ee2..5e7ffa64c6 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHealthIndicator.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHealthIndicator.java @@ -22,18 +22,13 @@ import java.util.Map; import javax.sql.DataSource; -import org.springframework.context.EnvironmentAware; -import org.springframework.core.env.Environment; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.StringUtils; /** * @author Dave Syer */ -public class SimpleHealthIndicator implements HealthIndicator>, - EnvironmentAware { - - private Environment environment; +public class SimpleHealthIndicator implements HealthIndicator> { private DataSource dataSource; @@ -65,18 +60,9 @@ public class SimpleHealthIndicator implements HealthIndicator