0

I'm seeing the following error during Tomcat shutdown:

Jan 04, 2015 4:14:31 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [] registered the JDBC driver [org.apache.derby.jdbc.AutoloadedDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

I understand Tomcat forcibly unregistered the driver to prevent a memory leak.

However, how to fix and who is responsible for fixing this issue -- me, Tomcat DBCP, or Derby?

I'm using Tomcat 7.0.47 and Derby 10.11.1.1

context.xml for Tomcat:

<Context>
  <Resource name="jdbc/db" auth="Container" type="javax.sql.DataSource"
               driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
               factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
               maxActive="100"
               minIdle="2"
               maxIdle="30"
               maxWait="10000"
               validationQuery="VALUES 1"
               testOnBorrow="true"
               removeAbandoned="true"
               url="jdbc:derby:dev;create=true"
               username="root"
               password="root"
               />
</Context>

Similar questions I found on Google referenced DERBY-4895, but that issue has been fixed a while ago.

Victor Lyuboslavsky
  • 9,882
  • 25
  • 87
  • 134

1 Answers1

0

You can simply ignore it, or you can create a ServletContextListener that deregisters the drivers at app shutdown:

public class MyContextListener implements ServletContextListener{

 @Override
 public void contextDestroyed(ServletContextEvent arg0) {
    System.out.println("App shutdown ...");

    System.out.println("Deregistering SQL-Drivers ...");
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        Driver driver = drivers.nextElement();
        try {
            DriverManager.deregisterDriver(driver);
            System.out.println(driver.getClass().getName());
        } catch (SQLException e) {
            System.err.println("Error deregistering driver " + driver.getClass().getName());
        }
    }
 }

 @Override
 public void contextInitialized(ServletContextEvent arg0) {
 }
}

Of course you need to add the listener to your web.xml, or annotate it with @WebListener.

Stefan
  • 12,108
  • 5
  • 47
  • 66