package org.springframework.cloud.service.relational;

import javax.sql.DataSource;

import org.springframework.cloud.service.ServiceConnectorConfig;
import org.springframework.cloud.service.common.RelationalServiceInfo;

/**
 *
 * @author Ramnivas Laddad
 * @author Scott Frederick
 *
 * @param <SI> the {@link RelationalServiceInfo} type for the underlying database service
 */
public class BasicDbcpPooledDataSourceCreator<SI extends RelationalServiceInfo> extends DbcpLikePooledDataSourceCreator<SI> {
	static final String DBCP2_BASIC_DATASOURCE = "org.apache.commons.dbcp2.BasicDataSource";

	@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");
	}
}

@@ -215,16 +215,80 @@
 eInfo;%0A%0A
+import static org.springframework.cloud.service.Util.hasClass;%0A%0A
 /**%0A *%0A 
@@ -831,16 +831,59 @@
 uery) %7B%0A
+%09%09if (hasClass(DBCP2_BASIC_DATASOURCE)) %7B%0A%09
 %09%09logger
@@ -966,16 +966,17 @@
 ing.%22);%0A
+%09
 %09%09org.ap
@@ -1063,16 +1063,17 @@
 urce();%0A
+%09
 %09%09setBas
@@ -1173,16 +1173,17 @@
 ery);%0A%09%09
+%09
 return n
@@ -1219,13 +1219,32 @@
 %22url%22);%0A
+%09%09%7D%0A%09%09return null;%0A
 %09%7D%0A%7D%0A

Check that Apache Commons DBCP2 is on the classpath before trying to use it.