09-Aug-2020 01:18:00.659 INFO [mysql-cj-abandoned-connection-cleanup] org.apache.catalina.loader.WebappClassLoader.findResourceInternal Illegal access: this web application instance has been stopped already. Could not load . The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.

mysql-cj-abandoned-connection-cleanup

![在这里插入图片描述](https://img-blog.csdnimg.cn/2020080901265638.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NoaW5hX1NZSA==,size_16,color_FFFFFF,t_70#pic_center)


学习ssm整合的时候一直在TOMCAT的日志中报出这个警告,虽然不影响,但是5秒就重复弹出来还是挺烦的。上百度上查找,答案寥寥无几最后在CSDN上找到了答案,要创建一个web监听类,主要是关闭数据库的连接。
package com.ssm.listener;

import com.mysql.cj.jdbc.AbandonedConnectionCleanupThread;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;

//修复DBCP的BUG,https://issues.apache.org/jira/browse/DBCP-332
public class MyServletContextListener implements ServletContextListener{

    public void contextInitialized(ServletContextEvent servletContextEvent) {

    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        //这里如果Web应用拥有多个数据库的连接,可以一并关闭
        Enumeration<Driver> drivers = DriverManager.getDrivers();
        Driver driver = null;
        while (drivers.hasMoreElements()) {
            try {
                driver = drivers.nextElement();
                DriverManager.deregisterDriver(driver);
            } catch (SQLException ex) {
            }
        }
        AbandonedConnectionCleanupThread.checkedShutdown();
    }
}

最后在web.xml中注册该类:

<listener>
    <listener-class>com.ssm.listener.MyServletContextListener</listener-class>
</listener>

解决方法来自文章:link

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐