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



优质内容筛选与推荐>>
1、[转自左潇龙的博客]设计模式详解(总纲)
2、MVC模式
3、C# HttpClient Cookie验证解决方法
4、centos6.x最小化安装后配置网络
5、rpm安装mysql之后启动 MySQL is not running, but PID file exists


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn