diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java index c803992d43..6f9c4ddd72 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java @@ -38,7 +38,7 @@ import org.springframework.util.StringUtils; abstract class DataSourceConfiguration { @SuppressWarnings("unchecked") - protected T createDataSource(DataSourceProperties properties, + protected static T createDataSource(DataSourceProperties properties, Class type) { return (T) properties.initializeDataSourceBuilder().type(type).build(); } @@ -47,8 +47,9 @@ abstract class DataSourceConfiguration { * Tomcat Pool DataSource configuration. */ @ConditionalOnClass(org.apache.tomcat.jdbc.pool.DataSource.class) + @ConditionalOnMissingBean(DataSource.class) @ConditionalOnProperty(name = "spring.datasource.type", havingValue = "org.apache.tomcat.jdbc.pool.DataSource", matchIfMissing = true) - static class Tomcat extends DataSourceConfiguration { + static class Tomcat { @Bean @ConfigurationProperties(prefix = "spring.datasource.tomcat") @@ -72,8 +73,9 @@ abstract class DataSourceConfiguration { * Hikari DataSource configuration. */ @ConditionalOnClass(HikariDataSource.class) + @ConditionalOnMissingBean(DataSource.class) @ConditionalOnProperty(name = "spring.datasource.type", havingValue = "com.zaxxer.hikari.HikariDataSource", matchIfMissing = true) - static class Hikari extends DataSourceConfiguration { + static class Hikari { @Bean @ConfigurationProperties(prefix = "spring.datasource.hikari") @@ -92,8 +94,9 @@ abstract class DataSourceConfiguration { * DBCP DataSource configuration. */ @ConditionalOnClass(org.apache.commons.dbcp2.BasicDataSource.class) + @ConditionalOnMissingBean(DataSource.class) @ConditionalOnProperty(name = "spring.datasource.type", havingValue = "org.apache.commons.dbcp2.BasicDataSource", matchIfMissing = true) - static class Dbcp2 extends DataSourceConfiguration { + static class Dbcp2 { @Bean @ConfigurationProperties(prefix = "spring.datasource.dbcp2")