問題是tomcat的版本問題,tomcat新檢測機制導致的這個問題,換版本可以解決問題,但不建議這么做,租用服務器不是你說換就換的。
其實問題根源是BasicDataSource,BasicDataSource類close()的一個Bug。
其實問題根源是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()
package cn.com.do1.component.common.jdbc;import org.apache.commons.dbcp.BasicDataSource;import java.sql.DriverManager;import java.sql.SQLException;import java.sql.SQLFeatureNotSupportedException;import java.util.logging.Logger;/*** Created by ao.ouyang on 15-11-18.*/public class BasicDataSourceExt extends BasicDataSource {public <T> T unwrap(Class<T> iface) throws SQLException {// TODO Auto-generated method stubreturn null;}public boolean isWrapperFor(Class<?> iface) throws SQLException {// TODO Auto-generated method stubreturn false;}public synchronized void close() throws SQLException {DriverManager.deregisterDriver(DriverManager.getDriver(url));super.close();}public Logger getParentLogger() throws SQLFeatureNotSupportedException {return null;}}
然后用 BasicDataSourceExt 替換spring配置文件中的數據源bean的class
