Skip to content

Spring Connection Pooling with DBCP

Recently I wanted to add a connection pool to my Spring Web Application. I decided to use Commons DBCP to provide the connection pool as I’m using the Spring JDBC wrapper classes. Googling around didn’t find any examples of how to set up DBCP, so I’ve written my findings here.

Adding a connection pool to a Spring app is simply a matter of specifying the relevant entries in the Spring servlet configuration file. The XML snippet below shows an example of how a database connection pool can easily be configured.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
  <property name="driverClassName">

  <property name="url">
  <property name="username">

  <property name="password">
  <property name="initialSize">

  <property name="maxActive">

  <property name="maxIdle">

Leave a Reply

Your email address will not be published. Required fields are marked *