Commit 8b61d151 authored by Stephane Nicoll's avatar Stephane Nicoll

Remove deprecated support for commons-dbcp 1

See gh-6787
parent 543498f0
...@@ -145,11 +145,6 @@ ...@@ -145,11 +145,6 @@
<artifactId>jersey-media-json-jackson</artifactId> <artifactId>jersey-media-json-jackson</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.apache.activemq</groupId> <groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId> <artifactId>activemq-broker</artifactId>
......
...@@ -101,8 +101,7 @@ public class DataSourceAutoConfiguration { ...@@ -101,8 +101,7 @@ public class DataSourceAutoConfiguration {
@Conditional(PooledDataSourceCondition.class) @Conditional(PooledDataSourceCondition.class)
@ConditionalOnMissingBean({ DataSource.class, XADataSource.class }) @ConditionalOnMissingBean({ DataSource.class, XADataSource.class })
@Import({ DataSourceConfiguration.Tomcat.class, DataSourceConfiguration.Hikari.class, @Import({ DataSourceConfiguration.Tomcat.class, DataSourceConfiguration.Hikari.class,
DataSourceConfiguration.Dbcp.class, DataSourceConfiguration.Dbcp2.class, DataSourceConfiguration.Dbcp2.class, DataSourceConfiguration.Generic.class })
DataSourceConfiguration.Generic.class })
protected static class PooledDataSourceConfiguration { protected static class PooledDataSourceConfiguration {
} }
......
...@@ -44,7 +44,6 @@ public class DataSourceBuilder { ...@@ -44,7 +44,6 @@ public class DataSourceBuilder {
private static final String[] DATA_SOURCE_TYPE_NAMES = new String[] { private static final String[] DATA_SOURCE_TYPE_NAMES = new String[] {
"org.apache.tomcat.jdbc.pool.DataSource", "org.apache.tomcat.jdbc.pool.DataSource",
"com.zaxxer.hikari.HikariDataSource", "com.zaxxer.hikari.HikariDataSource",
"org.apache.commons.dbcp.BasicDataSource", //deprecated
"org.apache.commons.dbcp2.BasicDataSource" }; "org.apache.commons.dbcp2.BasicDataSource" };
private Class<? extends DataSource> type; private Class<? extends DataSource> type;
......
...@@ -75,28 +75,6 @@ abstract class DataSourceConfiguration { ...@@ -75,28 +75,6 @@ abstract class DataSourceConfiguration {
} }
} }
@ConditionalOnClass(org.apache.commons.dbcp.BasicDataSource.class)
@ConditionalOnProperty(name = "spring.datasource.type", havingValue = "org.apache.commons.dbcp.BasicDataSource", matchIfMissing = true)
@Deprecated
static class Dbcp extends DataSourceConfiguration {
@Bean
@ConfigurationProperties("spring.datasource.dbcp")
public org.apache.commons.dbcp.BasicDataSource dataSource(
DataSourceProperties properties) {
org.apache.commons.dbcp.BasicDataSource dataSource = createDataSource(
properties, org.apache.commons.dbcp.BasicDataSource.class);
DatabaseDriver databaseDriver = DatabaseDriver
.fromJdbcUrl(properties.determineUrl());
String validationQuery = databaseDriver.getValidationQuery();
if (validationQuery != null) {
dataSource.setTestOnBorrow(true);
dataSource.setValidationQuery(validationQuery);
}
return dataSource;
}
}
@ConditionalOnClass(org.apache.commons.dbcp2.BasicDataSource.class) @ConditionalOnClass(org.apache.commons.dbcp2.BasicDataSource.class)
@ConditionalOnProperty(name = "spring.datasource.type", havingValue = "org.apache.commons.dbcp2.BasicDataSource", matchIfMissing = true) @ConditionalOnProperty(name = "spring.datasource.type", havingValue = "org.apache.commons.dbcp2.BasicDataSource", matchIfMissing = true)
static class Dbcp2 extends DataSourceConfiguration { static class Dbcp2 extends DataSourceConfiguration {
......
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.jdbc.metadata;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
/**
* {@link DataSourcePoolMetadata} for an Apache Commons DBCP {@link DataSource}.
*
* @author Stephane Nicoll
* @since 1.2.0
*/
@Deprecated
public class CommonsDbcpDataSourcePoolMetadata
extends AbstractDataSourcePoolMetadata<BasicDataSource> {
public CommonsDbcpDataSourcePoolMetadata(BasicDataSource dataSource) {
super(dataSource);
}
@Override
public Integer getActive() {
return getDataSource().getNumActive();
}
@Override
public Integer getMax() {
return getDataSource().getMaxActive();
}
@Override
public Integer getMin() {
return getDataSource().getMinIdle();
}
@Override
public String getValidationQuery() {
return getDataSource().getValidationQuery();
}
}
...@@ -77,28 +77,6 @@ public class DataSourcePoolMetadataProvidersConfiguration { ...@@ -77,28 +77,6 @@ public class DataSourcePoolMetadataProvidersConfiguration {
} }
@Configuration
@ConditionalOnClass(org.apache.commons.dbcp.BasicDataSource.class)
@Deprecated
static class CommonsDbcpPoolDataSourceMetadataProviderConfiguration {
@Bean
public DataSourcePoolMetadataProvider commonsDbcpPoolDataSourceMetadataProvider() {
return new DataSourcePoolMetadataProvider() {
@Override
public DataSourcePoolMetadata getDataSourcePoolMetadata(
DataSource dataSource) {
if (dataSource instanceof org.apache.commons.dbcp.BasicDataSource) {
return new CommonsDbcpDataSourcePoolMetadata(
(org.apache.commons.dbcp.BasicDataSource) dataSource);
}
return null;
}
};
}
}
@Configuration @Configuration
@ConditionalOnClass(BasicDataSource.class) @ConditionalOnClass(BasicDataSource.class)
static class CommonsDbcp2PoolDataSourceMetadataProviderConfiguration { static class CommonsDbcp2PoolDataSourceMetadataProviderConfiguration {
......
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.jdbc;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.junit.Test;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link CommonsDbcpDataSourceConfiguration}.
*
* @author Dave Syer
* @author Stephane Nicoll
*/
@Deprecated
public class CommonsDbcpDataSourceConfigurationTests {
private static final String PREFIX = "spring.datasource.dbcp.";
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@Test
public void testDataSourceExists() throws Exception {
this.context.register(CommonsDbcpDataSourceConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(DataSource.class)).isNotNull();
this.context.close();
}
@Test
public void testDataSourcePropertiesOverridden() throws Exception {
this.context.register(CommonsDbcpDataSourceConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "url:jdbc:foo//bar/spam");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testWhileIdle:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnBorrow:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnReturn:true");
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "timeBetweenEvictionRunsMillis:10000");
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "minEvictableIdleTimeMillis:12345");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "maxWait:1234");
this.context.refresh();
BasicDataSource ds = this.context.getBean(BasicDataSource.class);
assertThat(ds.getUrl()).isEqualTo("jdbc:foo//bar/spam");
assertThat(ds.getTestWhileIdle()).isTrue();
assertThat(ds.getTestOnBorrow()).isTrue();
assertThat(ds.getTestOnReturn()).isTrue();
assertThat(ds.getTimeBetweenEvictionRunsMillis()).isEqualTo(10000);
assertThat(ds.getMinEvictableIdleTimeMillis()).isEqualTo(12345);
assertThat(ds.getMaxWait()).isEqualTo(1234);
}
@Test
public void testDataSourceDefaultsPreserved() throws Exception {
this.context.register(CommonsDbcpDataSourceConfiguration.class);
this.context.refresh();
BasicDataSource ds = this.context.getBean(BasicDataSource.class);
assertThat(ds.getTimeBetweenEvictionRunsMillis())
.isEqualTo(GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
assertThat(ds.getMinEvictableIdleTimeMillis())
.isEqualTo(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
assertThat(ds.getMaxWait()).isEqualTo(GenericObjectPool.DEFAULT_MAX_WAIT);
}
@Configuration
@EnableConfigurationProperties
protected static class CommonsDbcpDataSourceConfiguration {
@Bean
@ConfigurationProperties(prefix = "spring.datasource.dbcp")
public DataSource dataSource() {
return DataSourceBuilder.create().type(BasicDataSource.class).build();
}
}
}
...@@ -137,30 +137,10 @@ public class DataSourceAutoConfigurationTests { ...@@ -137,30 +137,10 @@ public class DataSourceAutoConfigurationTests {
// Use Connection#isValid() // Use Connection#isValid()
} }
@Test
@Deprecated
public void commonsDbcpIsFallback() throws Exception {
org.apache.commons.dbcp.BasicDataSource dataSource = autoConfigureDataSource(
org.apache.commons.dbcp.BasicDataSource.class,
"org.apache.tomcat", "com.zaxxer.hikari");
assertThat(dataSource.getUrl()).isEqualTo("jdbc:hsqldb:mem:testdb");
}
@Test
@Deprecated
public void commonsDbcpValidatesConnectionByDefault() {
org.apache.commons.dbcp.BasicDataSource dataSource = autoConfigureDataSource(
org.apache.commons.dbcp.BasicDataSource.class,
"org.apache.tomcat", "com.zaxxer.hikari");
assertThat(dataSource.getTestOnBorrow()).isTrue();
assertThat(dataSource.getValidationQuery())
.isEqualTo(DatabaseDriver.HSQLDB.getValidationQuery());
}
@Test @Test
public void commonsDbcp2IsFallback() throws Exception { public void commonsDbcp2IsFallback() throws Exception {
BasicDataSource dataSource = autoConfigureDataSource(BasicDataSource.class, BasicDataSource dataSource = autoConfigureDataSource(BasicDataSource.class,
"org.apache.tomcat", "com.zaxxer.hikari", "org.apache.commons.dbcp."); "org.apache.tomcat", "com.zaxxer.hikari");
assertThat(dataSource.getUrl()).isEqualTo("jdbc:hsqldb:mem:testdb"); assertThat(dataSource.getUrl()).isEqualTo("jdbc:hsqldb:mem:testdb");
} }
...@@ -168,7 +148,7 @@ public class DataSourceAutoConfigurationTests { ...@@ -168,7 +148,7 @@ public class DataSourceAutoConfigurationTests {
public void commonsDbcp2ValidatesConnectionByDefault() throws Exception { public void commonsDbcp2ValidatesConnectionByDefault() throws Exception {
org.apache.commons.dbcp2.BasicDataSource dataSource = autoConfigureDataSource( org.apache.commons.dbcp2.BasicDataSource dataSource = autoConfigureDataSource(
org.apache.commons.dbcp2.BasicDataSource.class, "org.apache.tomcat", org.apache.commons.dbcp2.BasicDataSource.class, "org.apache.tomcat",
"com.zaxxer.hikari", "org.apache.commons.dbcp."); "com.zaxxer.hikari");
assertThat(dataSource.getTestOnBorrow()).isEqualTo(true); assertThat(dataSource.getTestOnBorrow()).isEqualTo(true);
assertThat(dataSource.getValidationQuery()).isNull(); // Use Connection#isValid() assertThat(dataSource.getValidationQuery()).isNull(); // Use Connection#isValid()
} }
......
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.jdbc.metadata;
import org.apache.commons.dbcp.BasicDataSource;
import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link CommonsDbcpDataSourcePoolMetadata}.
*
* @author Stephane Nicoll
*/
@Deprecated
public class CommonsDbcpDataSourcePoolMetadataTests
extends AbstractDataSourcePoolMetadataTests<CommonsDbcpDataSourcePoolMetadata> {
private CommonsDbcpDataSourcePoolMetadata dataSourceMetadata;
@Before
public void setup() {
this.dataSourceMetadata = createDataSourceMetadata(0, 2);
}
@Override
protected CommonsDbcpDataSourcePoolMetadata getDataSourceMetadata() {
return this.dataSourceMetadata;
}
@Test
public void getPoolUsageWithNoCurrent() {
CommonsDbcpDataSourcePoolMetadata dsm = new CommonsDbcpDataSourcePoolMetadata(
createDataSource()) {
@Override
public Integer getActive() {
return null;
}
};
assertThat(dsm.getUsage()).isNull();
}
@Test
public void getPoolUsageWithNoMax() {
CommonsDbcpDataSourcePoolMetadata dsm = new CommonsDbcpDataSourcePoolMetadata(
createDataSource()) {
@Override
public Integer getMax() {
return null;
}
};
assertThat(dsm.getUsage()).isNull();
}
@Test
public void getPoolUsageWithUnlimitedPool() {
DataSourcePoolMetadata unlimitedDataSource = createDataSourceMetadata(0, -1);
assertThat(unlimitedDataSource.getUsage()).isEqualTo(Float.valueOf(-1F));
}
@Override
public void getValidationQuery() {
BasicDataSource dataSource = createDataSource();
dataSource.setValidationQuery("SELECT FROM FOO");
assertThat(new CommonsDbcpDataSourcePoolMetadata(dataSource).getValidationQuery())
.isEqualTo("SELECT FROM FOO");
}
private CommonsDbcpDataSourcePoolMetadata createDataSourceMetadata(int minSize,
int maxSize) {
BasicDataSource dataSource = createDataSource();
dataSource.setMinIdle(minSize);
dataSource.setMaxActive(maxSize);
return new CommonsDbcpDataSourcePoolMetadata(dataSource);
}
private BasicDataSource createDataSource() {
return (BasicDataSource) initializeBuilder().type(BasicDataSource.class).build();
}
}
...@@ -57,7 +57,6 @@ ...@@ -57,7 +57,6 @@
<commons-beanutils.version>1.9.2</commons-beanutils.version> <commons-beanutils.version>1.9.2</commons-beanutils.version>
<commons-collections.version>3.2.2</commons-collections.version> <commons-collections.version>3.2.2</commons-collections.version>
<commons-codec.version>1.10</commons-codec.version> <commons-codec.version>1.10</commons-codec.version>
<commons-dbcp.version>1.4</commons-dbcp.version>
<commons-dbcp2.version>2.1.1</commons-dbcp2.version> <commons-dbcp2.version>2.1.1</commons-dbcp2.version>
<commons-digester.version>2.1</commons-digester.version> <commons-digester.version>2.1</commons-digester.version>
<commons-pool.version>1.6</commons-pool.version> <commons-pool.version>1.6</commons-pool.version>
...@@ -823,11 +822,6 @@ ...@@ -823,11 +822,6 @@
<artifactId>commons-codec</artifactId> <artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version> <version>${commons-codec.version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>${commons-dbcp.version}</version>
</dependency>
<dependency> <dependency>
<groupId>commons-digester</groupId> <groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId> <artifactId>commons-digester</artifactId>
......
...@@ -152,11 +152,6 @@ ...@@ -152,11 +152,6 @@
<artifactId>HikariCP</artifactId> <artifactId>HikariCP</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>de.flapdoodle.embed</groupId> <groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId> <artifactId>de.flapdoodle.embed.mongo</artifactId>
......
...@@ -2700,10 +2700,8 @@ Here's the algorithm for choosing a specific implementation: ...@@ -2700,10 +2700,8 @@ Here's the algorithm for choosing a specific implementation:
* We prefer the Tomcat pooling `DataSource` for its performance and concurrency, so if * We prefer the Tomcat pooling `DataSource` for its performance and concurrency, so if
that is available we always choose it. that is available we always choose it.
* Otherwise, if HikariCP is available we will use it. * Otherwise, if HikariCP is available we will use it.
* If neither the Tomcat pooling datasource nor HikariCP are available and if Commons DBCP * If neither the Tomcat pooling datasource nor HikariCP are available and if Commons
is available we will use it, but we don't recommend it in production and its support DBCP2 is available we will use it.
is deprecated.
* Lastly, if Commons DBCP2 is available we will use it.
If you use the `spring-boot-starter-jdbc` or `spring-boot-starter-data-jpa` If you use the `spring-boot-starter-jdbc` or `spring-boot-starter-data-jpa`
'`starters`' you will automatically get a dependency to `tomcat-jdbc`. '`starters`' you will automatically get a dependency to `tomcat-jdbc`.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment