The web application [ROOT] 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.
应用程序跑的没问题,但是强制解除注册了?用的 mybatis,是要我手动解除么?
1
ixiaohei 2017-05-17 23:59:48 +08:00
这个是 tomcat 关闭时候检查内存泄漏的提示,不用管就行了
|
3
Jerry09 2017-05-18 00:30:22 +08:00 via iPhone
你推出之后看进程管理里面有没有 Java 内存泄漏了应该是
|
4
honeycomb 2017-05-18 01:17:15 +08:00 via Android
有些很旧的 JDBC 驱动会有关不掉的问题
|
5
tianshuang 2017-05-18 09:20:14 +08:00
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Enumeration; public class AppServletContextListener implements ServletContextListener { private static final Logger logger = LogManager.getLogger(); @Override public void contextInitialized(ServletContextEvent sce) { } @Override public void contextDestroyed(ServletContextEvent sce) { // This manually deregisters JDBC driver, which prevents Tomcat from complaining about memory leaks to this class Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver driver = drivers.nextElement(); try { DriverManager.deregisterDriver(driver); logger.log(Level.INFO, String.format("deregistering jdbc driver: %s", driver)); } catch (SQLException e) { logger.log(Level.ERROR, String.format("Error deregistering driver %s", driver), e); } } } } |