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.



問題是tomcat的版本問題,tomcat新檢測機制導致的這個問題,換版本可以解決問題,但不建議這么做,租用服務器不是你說換就換的。
其實問題根源是BasicDataSource,BasicDataSource類close()的一個Bug。
BasicDataSource's method close() doesn't deregister JDBC driver. This causes permgen memory leaks in web server environments, during context reloads. For example, using Tomcat 6.0.26 with Spring, and BasicDataSource declared in Spring context, there is a message printed at web application reload: 

SEVERE: A web application registered the JBDC 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.


解決方法:

繼承org.apache.commons.dbcp.BasicDataSource 重寫close()


  
  
  
          
  1. package cn.com.do1.component.common.jdbc;
  2. import org.apache.commons.dbcp.BasicDataSource;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import java.sql.SQLFeatureNotSupportedException;
  6. import java.util.logging.Logger;
  7. /**
  8. * Created by ao.ouyang on 15-11-18.
  9. */
  10. public class BasicDataSourceExt extends BasicDataSource {
  11.    @Override
  12.    public <T> T unwrap(Class<T> iface) throws SQLException {
  13.        // TODO Auto-generated method stub
  14.        return null;
  15.    }
  16.    @Override
  17.    public boolean isWrapperFor(Class<?> iface) throws SQLException {
  18.        // TODO Auto-generated method stub
  19.        return false;
  20.    }
  21.    @Override
  22.    public synchronized void close() throws SQLException {
  23.        DriverManager.deregisterDriver(DriverManager.getDriver(url));
  24.        super.close();
  25.    }
  26.    @Override
  27.    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
  28.        return null;
  29.    }
  30. }






然后用 BasicDataSourceExt 替換spring配置文件中的數據源bean的class




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 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. The web application registered the 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. 解決:The web application [] registered the 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. 啟動錯誤筆記:DruidDriver] but failed to unregister it when the web application was stopped,To prevent a memory leak, the JDBC Driver has been forcibly unregistered. registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. 嚴重: The web application [] registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDB GlassFish To prevent a memory leak, the JDBC Driver has been forcibly unregistered tomcat啟動報錯:To prevent a memory leak, the JDBC Driver has been forcibly unregistered. Tomcat出現To prevent a memory leak, the JDBC Driver has been forcibly unregistered.問題的一種情況記錄 registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. (轉)
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM