Follow this Spring configuration recipe for integrating BoneCP into your application. This is an example of how to fetch a JDBC connection directly for use via Spring (i.e. dealing with the datasource yourself).
Application Context
<!-- BoneCP configuration -->
<bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://127.0.0.1/yourdb" />
<property name="username" value="root"/>
<property name="password" value="abcdefgh"/>
<property name="idleConnectionTestPeriod" value="60"/>
<property name="idleMaxAge" value="240"/>
<property name="maxConnectionsPerPartition" value="30"/>
<property name="minConnectionsPerPartition" value="10"/>
<property name="partitionCount" value="3"/>
<property name="acquireIncrement" value="5"/>
<property name="statementsCacheSize" value="100"/>
<property name="releaseHelperThreads" value="3"/>
</bean>
Code:
Make sure you define the class below (either via explicit listing of the class name or via <component-scan>.
@Component
public class Foo {
@Autowired
DataSource ds;
public void testBoneCP() throws SQLException {
Connection connection = ds.getConnection();
System.out.println(connection); // do something with the connection here..
}
}