To prevent a memory leak, the JDBC Driver has been forcibly unregistered

后端 未结 14 1471
执念已碎
执念已碎 2020-11-22 02:15

I am getting this message when I run my web application. It runs fine but I get this message during shutdown.

SEVERE: A web application registered the

14条回答
  •  花落未央
    2020-11-22 03:22

    I found that implementing a simple destroy() method to de-register any JDBC drivers works nicely.

    /**
     * Destroys the servlet cleanly by unloading JDBC drivers.
     * 
     * @see javax.servlet.GenericServlet#destroy()
     */
    public void destroy() {
        String prefix = getClass().getSimpleName() +" destroy() ";
        ServletContext ctx = getServletContext();
        try {
            Enumeration drivers = DriverManager.getDrivers();
            while(drivers.hasMoreElements()) {
                DriverManager.deregisterDriver(drivers.nextElement());
            }
        } catch(Exception e) {
            ctx.log(prefix + "Exception caught while deregistering JDBC drivers", e);
        }
        ctx.log(prefix + "complete");
    }
    

提交回复
热议问题