Laran Evans
Laran Evans

Reputation: 1313

Tomcat fails to start because of jdbc driver loading

Here's the relevant portion of the tomcat startup log:

SEVERE: Context [/f360] startup failed due to previous errors
Apr 8, 2010 6:45:56 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: A web application registered the JBDC driver [org.apache.derby.jdbc.ClientDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Apr 8, 2010 6:45:56 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: A web application registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Apr 8, 2010 6:45:56 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: A web application registered the JBDC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

The problem that it causes is that it basically causes the web app to fail to startup properly.

Any ideas how to fix this?

Upvotes: 17

Views: 56225

Answers (4)

ylev
ylev

Reputation: 2569

Sometimes, especially when using Spring application on Tomcat, the error message is misleading - when there is no relation to any JDBC driver error at all but only a failure of some application BEAN init-method (or @PostConstruct). The error stack trace is hidden and appears only in tomcat/logs/localhost.xxx file. Just be aware of this behavior. It costed me a lot of time.

Upvotes: 7

Mond Raymond
Mond Raymond

Reputation: 330

Clearly this is a bug in the JDBC provider stack. But anyway, I used some similar code in Jetty:

public class CleanupContextListener implements ServletContextListener {
    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        Logger logger = Logger.getLogger("CleanupContextListener");
        Enumeration<Driver> drivers = DriverManager.getDrivers();
        while (drivers.hasMoreElements()) {
            Driver driver = drivers.nextElement();
            ClassLoader driverclassLoader = driver.getClass().getClassLoader();
            ClassLoader thisClassLoader = this.getClass().getClassLoader();
            if (driverclassLoader != null && thisClassLoader != null &&  driverclassLoader.equals(thisClassLoader)) {
                try {
                    logger.warn("Deregistering: " + driver);
                    DriverManager.deregisterDriver(driver);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {}    
}

Upvotes: 6

Doug
Doug

Reputation: 61

If it's the DBCP problem then stop tomcat, kill any remaining process (in case you have more than one tomcat running), delete the tomcat temp directory (and perhaps work directory) and try again.

Upvotes: 5

rgielen
rgielen

Reputation: 186

The SEVERE messages regarding JDBC drivers are caused by a DBCP issue. See DBCP-332

Upvotes: 4

Related Questions