From a512bcf7662e28c716f1dcaa33036d04e34e63c2 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 1 Sep 2014 11:26:05 -0700 Subject: [PATCH] Always auto-configure pool metadata providers Import DataSourcePoolMetadataProvidersConfiguration from DataSourceAutoConfiguration so that PoolMetadataProviders are configured even if actuator is not used. --- .../autoconfigure/DataSourceMetricsAutoConfiguration.java | 3 --- .../DataSourceMetricsAutoConfigurationTests.java | 4 +++- .../boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/DataSourceMetricsAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/DataSourceMetricsAutoConfiguration.java index 2ccc81382e..4c88f7e501 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/DataSourceMetricsAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/DataSourceMetricsAutoConfiguration.java @@ -25,9 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider; -import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Import; /** * {@link EnableAutoConfiguration Auto-configuration} that provides metrics on dataSource @@ -38,7 +36,6 @@ import org.springframework.context.annotation.Import; */ @ConditionalOnBean(DataSource.class) @AutoConfigureAfter(DataSourceAutoConfiguration.class) -@Import(DataSourcePoolMetadataProvidersConfiguration.class) public class DataSourceMetricsAutoConfiguration { @Bean diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/DataSourceMetricsAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/DataSourceMetricsAutoConfigurationTests.java index 54999b3b7e..c627e68fb3 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/DataSourceMetricsAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/DataSourceMetricsAutoConfigurationTests.java @@ -32,6 +32,7 @@ import org.springframework.boot.actuate.endpoint.PublicMetrics; import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -136,7 +137,8 @@ public class DataSourceMetricsAutoConfigurationTests { if (config.length > 0) { this.context.register(config); } - this.context.register(DataSourceMetricsAutoConfiguration.class); + this.context.register(DataSourcePoolMetadataProvidersConfiguration.class, + DataSourceMetricsAutoConfiguration.class); this.context.refresh(); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java index 5a68991a21..981397d438 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java @@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerPostProcessor.Registrar; +import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -54,7 +55,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; @Configuration @ConditionalOnClass({ DataSource.class, EmbeddedDatabaseType.class }) @EnableConfigurationProperties(DataSourceProperties.class) -@Import(Registrar.class) +@Import({ Registrar.class, DataSourcePoolMetadataProvidersConfiguration.class }) public class DataSourceAutoConfiguration { /**