From c10b15ece320a883ef222886d7856d839fe1f288 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Thu, 15 Nov 2018 14:45:03 -0600 Subject: [PATCH] Check that Apache Commons DBCP2 is on the classpath before trying to use it. --- .../BasicDbcpPooledDataSourceCreator.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/relational/BasicDbcpPooledDataSourceCreator.java b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/relational/BasicDbcpPooledDataSourceCreator.java index 34fcdf5c..ddfc0399 100644 --- a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/relational/BasicDbcpPooledDataSourceCreator.java +++ b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/relational/BasicDbcpPooledDataSourceCreator.java @@ -5,6 +5,8 @@ import org.springframework.cloud.service.ServiceConnectorConfig; import org.springframework.cloud.service.common.RelationalServiceInfo; +import static org.springframework.cloud.service.Util.hasClass; + /** * * @author Ramnivas Laddad @@ -18,9 +20,12 @@ public class BasicDbcpPooledDataSourceCreator @Override public DataSource create(RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, String driverClassName, String validationQuery) { - logger.info("Found DBCP2 on the classpath. Using it for DataSource connection pooling."); - org.apache.commons.dbcp2.BasicDataSource ds = new org.apache.commons.dbcp2.BasicDataSource(); - setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery); - return new UrlDecodingDataSource(ds, "url"); + if (hasClass(DBCP2_BASIC_DATASOURCE)) { + logger.info("Found DBCP2 on the classpath. Using it for DataSource connection pooling."); + org.apache.commons.dbcp2.BasicDataSource ds = new org.apache.commons.dbcp2.BasicDataSource(); + setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery); + return new UrlDecodingDataSource(ds, "url"); + } + return null; } }