title: Tomcat 5.5 DBCP Connection Pool DataSource is closed
body: <p>I'm developing a Spring web app with Spring Data JPA and Hibernate, running on Tomcat 5.5. The Tomcat uses DBCP for connection pooling. </p>
  
  <p>The pool is defined like this:</p>
  
  <pre><code>&lt;Resource auth="Container" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
          factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
          logAbandoned="true" maxActive="100" maxIdle="30" maxWait="10000"
          minIdle="3" name="..." password="..." removeAbandoned="true"
          type="javax.sql.DataSource"
          url="..." username="..." validationQuery="select 1" /&gt;
  </code></pre>
  
  <p>On the Java side I get the Datasource via JNDI and Spring manages the object as a singelton and it will only be used to create the 
  EntityManagerFactory.</p>
  
  <p>Now my problem. When I first deploy the app on the freshly started Tomcat everything works fine. If I hot-deploy the app for the first time everything still works fine. But then if I hot-deploy for a second time I get following exception:</p>
  
  <pre><code>java.sql.SQLException: Data source is closed
  at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1362)
  at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
  </code></pre>
  
  <p>Any idea is appreciated, thanks!</p>
  
  <p><strong>Update:</strong> I tried it with Tomcat 7.0.12, which was lying around on my machine and had the same problem. I've than switched from commons-dbcp to Tomcat JDBC Connection Pool and the problem was gone on both Tomcat 5.5 and Tomcat 7. It now seems to me that there is a bug in commons-dbcp or Spring doesn't play nice with it? Does somebody know more about this?</p>