Skip to content

Commit

Permalink
Check that Apache Commons DBCP2 is on the classpath before trying to …
Browse files Browse the repository at this point in the history
…use it.
  • Loading branch information
scottfrederick committed Nov 15, 2018
1 parent fea3b37 commit c10b15e
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,9 +20,12 @@ public class BasicDbcpPooledDataSourceCreator<SI extends RelationalServiceInfo>
@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;
}
}

0 comments on commit c10b15e

Please sign in to comment.