mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Deprecate commons-dbcp 1
Closes gh-6787
This commit is contained in:
parent
0b9283c3cd
commit
cf28663cd7
@ -269,8 +269,8 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- Annotation processing -->
|
||||
|
@ -26,7 +26,7 @@ import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class DataSourceBuilder {
|
||||
private static final String[] DATA_SOURCE_TYPE_NAMES = new String[] {
|
||||
"org.apache.tomcat.jdbc.pool.DataSource",
|
||||
"com.zaxxer.hikari.HikariDataSource",
|
||||
"org.apache.commons.dbcp.BasicDataSource",
|
||||
"org.apache.commons.dbcp.BasicDataSource", //deprecated
|
||||
"org.apache.commons.dbcp2.BasicDataSource" };
|
||||
|
||||
private Class<? extends DataSource> type;
|
||||
|
@ -77,6 +77,7 @@ 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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* 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.
|
||||
@ -26,6 +26,7 @@ import org.apache.commons.dbcp.BasicDataSource;
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@Deprecated
|
||||
public class CommonsDbcpDataSourcePoolMetadata
|
||||
extends AbstractDataSourcePoolMetadata<BasicDataSource> {
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* 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.
|
||||
@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.jdbc.metadata;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -78,7 +78,8 @@ public class DataSourcePoolMetadataProvidersConfiguration {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(BasicDataSource.class)
|
||||
@ConditionalOnClass(org.apache.commons.dbcp.BasicDataSource.class)
|
||||
@Deprecated
|
||||
static class CommonsDbcpPoolDataSourceMetadataProviderConfiguration {
|
||||
|
||||
@Bean
|
||||
@ -87,9 +88,9 @@ public class DataSourcePoolMetadataProvidersConfiguration {
|
||||
@Override
|
||||
public DataSourcePoolMetadata getDataSourcePoolMetadata(
|
||||
DataSource dataSource) {
|
||||
if (dataSource instanceof BasicDataSource) {
|
||||
if (dataSource instanceof org.apache.commons.dbcp.BasicDataSource) {
|
||||
return new CommonsDbcpDataSourcePoolMetadata(
|
||||
(BasicDataSource) dataSource);
|
||||
(org.apache.commons.dbcp.BasicDataSource) dataSource);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -99,7 +100,7 @@ public class DataSourcePoolMetadataProvidersConfiguration {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(org.apache.commons.dbcp2.BasicDataSource.class)
|
||||
@ConditionalOnClass(BasicDataSource.class)
|
||||
static class CommonsDbcp2PoolDataSourceMetadataProviderConfiguration {
|
||||
|
||||
@Bean
|
||||
@ -108,9 +109,9 @@ public class DataSourcePoolMetadataProvidersConfiguration {
|
||||
@Override
|
||||
public DataSourcePoolMetadata getDataSourcePoolMetadata(
|
||||
DataSource dataSource) {
|
||||
if (dataSource instanceof org.apache.commons.dbcp2.BasicDataSource) {
|
||||
if (dataSource instanceof BasicDataSource) {
|
||||
return new CommonsDbcp2DataSourcePoolMetadata(
|
||||
(org.apache.commons.dbcp2.BasicDataSource) dataSource);
|
||||
(BasicDataSource) dataSource);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Deprecated
|
||||
public class CommonsDbcpDataSourceConfigurationTests {
|
||||
|
||||
private static final String PREFIX = "spring.datasource.dbcp.";
|
||||
|
@ -30,7 +30,7 @@ import java.util.logging.Logger;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -138,15 +138,19 @@ public class DataSourceAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void commonsDbcpIsFallback() throws Exception {
|
||||
BasicDataSource dataSource = autoConfigureDataSource(BasicDataSource.class,
|
||||
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() {
|
||||
BasicDataSource dataSource = autoConfigureDataSource(BasicDataSource.class,
|
||||
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())
|
||||
@ -155,9 +159,8 @@ public class DataSourceAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void commonsDbcp2IsFallback() throws Exception {
|
||||
org.apache.commons.dbcp2.BasicDataSource dataSource = autoConfigureDataSource(
|
||||
org.apache.commons.dbcp2.BasicDataSource.class, "org.apache.tomcat",
|
||||
"com.zaxxer.hikari", "org.apache.commons.dbcp.");
|
||||
BasicDataSource dataSource = autoConfigureDataSource(BasicDataSource.class,
|
||||
"org.apache.tomcat", "com.zaxxer.hikari", "org.apache.commons.dbcp.");
|
||||
assertThat(dataSource.getUrl()).isEqualTo("jdbc:hsqldb:mem:testdb");
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import java.util.Random;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -36,6 +36,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.jmx.export.MBeanExporter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link JndiDataSourceAutoConfiguration}
|
||||
@ -120,7 +121,7 @@ public class JndiDataSourceAutoConfigurationTests {
|
||||
@Test
|
||||
public void standardDataSourceIsNotExcludedFromExport()
|
||||
throws IllegalStateException, NamingException {
|
||||
DataSource dataSource = new org.apache.commons.dbcp.BasicDataSource();
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
configureJndi("foo", dataSource);
|
||||
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jdbc;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
|
||||
/**
|
||||
* {@link BasicDataSource} used for testing.
|
||||
|
@ -27,6 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Deprecated
|
||||
public class CommonsDbcpDataSourcePoolMetadataTests
|
||||
extends AbstractDataSourcePoolMetadataTests<CommonsDbcpDataSourcePoolMetadata> {
|
||||
|
||||
|
@ -594,7 +594,6 @@ content into your application; rather pick only the properties that you need.
|
||||
spring.datasource.data= # Data (DML) script resource reference.
|
||||
spring.datasource.data-username= # User of the database to execute DML scripts (if different).
|
||||
spring.datasource.data-password= # Password of the database to execute DML scripts (if different).
|
||||
spring.datasource.dbcp.*= # Commons DBCP specific settings
|
||||
spring.datasource.dbcp2.*= # Commons DBCP2 specific settings
|
||||
spring.datasource.driver-class-name= # Fully qualified name of the JDBC driver. Auto-detected based on the URL by default.
|
||||
spring.datasource.hikari.*= # Hikari specific settings
|
||||
|
@ -2690,7 +2690,8 @@ Here's the algorithm for choosing a specific implementation:
|
||||
that is available we always choose it.
|
||||
* Otherwise, if HikariCP is available we will use it.
|
||||
* If neither the Tomcat pooling datasource nor HikariCP are available and if Commons DBCP
|
||||
is available we will use it, but we don't recommend it in production.
|
||||
is available we will use it, but we don't recommend it in production and its support
|
||||
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`
|
||||
@ -2730,9 +2731,8 @@ See {sc-spring-boot-autoconfigure}/jdbc/DataSourceProperties.{sc-ext}[`DataSourc
|
||||
for more of the supported options. These are the standard options that work regardless of
|
||||
the actual implementation. It is also possible to fine-tune implementation-specific
|
||||
settings using their respective prefix (`+spring.datasource.tomcat.*+`,
|
||||
`+spring.datasource.hikari.*+`, `+spring.datasource.dbcp.*+` and
|
||||
`+spring.datasource.dbcp2.*+`). Refer to the documentation of the connection pool
|
||||
implementation you are using for more details.
|
||||
`+spring.datasource.hikari.*+`, and `+spring.datasource.dbcp2.*+`). Refer to the
|
||||
documentation of the connection pool implementation you are using for more details.
|
||||
|
||||
For instance, if you are using the
|
||||
http://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html#Common_Attributes[Tomcat connection pool]
|
||||
|
Loading…
Reference in New Issue
Block a user