Tomcat fails to start because of jdbc driver loading

↘锁芯ラ 提交于 2019-11-28 06:59:04

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) {}    

}

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.

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

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.

Regards, Yosi Lev

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!