register the mysql_registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it wh...

问题是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()

packagecn.com.do1.component.common.jdbc;

importorg.apache.commons.dbcp.BasicDataSource;

importjava.sql.DriverManager;

importjava.sql.SQLException;

importjava.sql.SQLFeatureNotSupportedException;

importjava.util.logging.Logger;

/**

* Created by ao.ouyang on 15-11-18.

*/

publicclassBasicDataSourceExtextendsBasicDataSource{

@Override

publicT unwrap(Classiface)throwsSQLException{

// TODO Auto-generated method stub

returnnull;

}

@Override

publicbooleanisWrapperFor(Class>iface)throwsSQLException{

// TODO Auto-generated method stub

returnfalse;

}

@Override

publicsynchronizedvoidclose()throwsSQLException{

DriverManager.deregisterDriver(DriverManager.getDriver(url));

super.close();

}

@Override

publicLoggergetParentLogger()throwsSQLFeatureNotSupportedException{

returnnull;

}

}

然后用BasicDataSourceExt 替换spring配置文件中的数据源bean的class

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值