registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it

寒假时在家看视频学习ssh,第一次将它们整合在一起,就出了问题:

 

严重: The web application [/] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

2012-2-15 15:25:22 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads

严重: The web application [/] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.

 

 

我用的是strut2.2.3+hibernate3+spring2.5.6+tomcat7.0.22+mysql5

 

看tomcat的启动信息是,应用程序注册了jdbc驱动,但是结束时无法注销,tomcat于是为防止内存泄露,强制注销了,

网上说是DBCP的bug

 

于是按https://issues.apache.org/jira/browse/DBCP-332上讲的

 

另外写一个类,继承org.apache.commons.dbcp.BasicDataSource来注销jdbcimport java.sql.DriverManager;

import java.sql.SQLException;

import org.apache.commons.dbcp.BasicDataSource;

public class XBasicDataSource extends BasicDataSource 
{
    @Override
    public synchronized void close() throws SQLException {
        DriverManager.deregisterDriver(DriverManager.getDriver(url));
        super.close();
    }
}

 于是问题终于解决了!不知还有没更好的方法?

你可能感兴趣的:(driver)