The web application registered the 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.
最近使用了最新版的tomcat9,使用jdbc链接mysql数据库。关闭tomcat过程中出现警告
13-Sep-2017 22:22:54.369 WARNING [main] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [license] 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.
时间有限没有去追源码,网上的说法:
tomcat6最新版本引入内存溢出检测阻止机制,检测到jdbc在tomcat运行时进行注册,但是当tomcat停止时没有解除注册。
原因是在tomcat停止之前没注销驱动。
网上有的方式是重写org.apache.commons.dbcp.BasicDataSource,这个不推荐。既然是容器级别的事件,那就从事件入手。
@WebListener
public class AppContextListener implements ServletContextListener{ public void contextDestroyed(ServletContextEvent event) {
try{
while(DriverManager.getDrivers().hasMoreElements()){
DriverManager.deregisterDriver(DriverManager.getDrivers().nextElement());
}
}catch(Exception e){
e.printStackTrace();
}
} public void contextInitialized(ServletContextEvent event) {
ServletContext context = event.getServletContext();
String rootPath = context.getRealPath("/");
System.setProperty("rootPath", rootPath); //logger.info("global setting,rootPath:{}",rootPath);
//logger.info("deployed on architecture:{},operation System:{},version:{}",
// System.getProperty("os.arch"), System.getProperty("os.name"),
// System.getProperty("os.version"));
//logger.info("app startup completed....");
}
}
Tomcat在停止web应用的时候会调用contextDestroyed方法,加入你的项目,即可在tomcat关闭时注销已经注册的JDBC驱动。
以上代码适用于servlet3.0 web容器,servlet 2.5容器需要在web.xml添加配置文件。
servlet容器2.5用法
public class AppContextListener implements ServletContextListener{
public void contextDestroyed(ServletContextEvent event) {
try{
while(DriverManager.getDrivers().hasMoreElements()){
DriverManager.deregisterDriver(DriverManager.getDrivers().nextElement());
}
}catch(Exception e){
e.printStackTrace();
}
}
public void contextInitialized(ServletContextEvent event) {
ServletContext context = event.getServletContext();
String rootPath = context.getRealPath("/");
System.setProperty("rootPath", rootPath);
//logger.info("global setting,rootPath:{}",rootPath);
//logger.info("deployed on architecture:{},operation System:{},version:{}",
// System.getProperty("os.arch"), System.getProperty("os.name"),
// System.getProperty("os.version"));
//logger.info("app startup completed....");
}
}
web.xml
<web-app>
<listener>
<listener-class>com.xxxx.init.AppContextListener</listener-class>
</listener>
</web-app>
至此,问题解决。
The web application registered the 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.的更多相关文章
- The web application [ ] registered the JDBC driver [net.sourceforge.jtds.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver
出现以下错误时,我找了很多方法,都未解决,网上有很多,最后我实在无奈,怀疑会不会是Tomcat的原因,更换了一个版本之后就好了.The web application [ ] registered t ...
- 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.
问题是tomcat的版本问题,tomcat新检测机制导致的这个问题,换版本可以解决问题,但不建议这么做,租用服务器不是你说换就换的.其实问题根源是BasicDataSource,BasicDataSo ...
- 解决:The web application [] registered the 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.
问题描述 在将Spring Boot程序打包生成的war包部署到Tomcat后,启动Tomcat时总是报错,但是直接在IDEA中启动Application或者用"java -jar" ...
- registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. (转)
最近项目中遇见一问题,在开发环境没有问题的代码,到了生产环境就会报如下错误: 严重: A web application registered the JBDC driver [oracle.jd ...
- 严重: The web application [] registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDB
idea项目启动报如下错误, 网上的方法都试了都没用, 一直没解决, 干掉项目, 重新从svn检出就好了...坑 啊 Root WebApplicationContext: initializatio ...
- registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped.
最近在用maven整合SSH做个人主页时候,在eclipse里面使用tomcat7插件发布项目是没有问题的,但当打包成war之后,使用tomcat7单独发布项目,就出现了以下的错误. 严重: Cont ...
- The web application [/codeMarket] registered the JBDC driver[.........] but failed to unregister it when the web application was stopped. To prevent
如果你报错了上面的这个严重,那么你的tomcat版本一定是在6.0.25之上的 原因:tomcat 6.025以后在sever.xml中引入了内存泄露侦测,对于垃圾回收不能处理的对像,它就会做日志. ...
- [tomcat启动报错]registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped
环境:一个tomcat ,一个工程配置了多数据源,在启动的时候报如下错误: SEVERE: The web application [/qdp-resource-job] registered the ...
- Tomcat运行一段时间后,自动停止关闭,To prevent a memory leak,Druid 数据库连接自动关闭, the JDBC Driver has been forcibly unregistered.
1. Tomcat 错误日志 tail -100f tomcat9/logs/catalina.out 21-Sep-2017 23:05:39.301 INFO [Thread-5] org.apa ...
随机推荐
- 编译ijkplayer后直播无声音
打开:ijkplayer-android/config/module-lite.sh 文件: 你要把neyllow打开,默认是关闭的,如下: export COMMON_FF_CFG_FLAGS=&q ...
- java基础回忆、复习(一)
一:浅拷贝与深拷贝: 对于基本数据类型,直接进行拷贝,String类型,有两种拷贝方式: 1:直接将原对象中的name的引用值拷贝给新对象的name字段.<浅拷贝> 2:根据原对象中的na ...
- openstack创建虚拟流程、各组件介绍
登录界面或命令行通过RESTful API向keystone获取认证信息. keystone通过用户请求认证信息,并生成auth-token返回给对应的认证请求. 界面或命令行通过RESTful AP ...
- oo第一次总结博客
一. 多项式求导问题描述 基本概念的声明: 带符号整数 支持前导 0 的带符号整数,符号可忽略,如:+02.-16.19260817 等. 因子 变量因子 幂函数 一般形式 由自变量x和指数组成,指数 ...
- Maven 错误 :The POM for com.xxx:jar:0.0.1-SNAPSHOT is invalid, transitive dependencies (if any) will not be available
一个大的maven 项目,结构是一个根pom,下面几个小的module,包括了appservice-darc,appservice-entity等,其中appservice-darc 依赖了 apps ...
- 一些常见的Java面试题 & 面试感悟
< 前言 > 近期在面试,深感这个行业的浮躁,一些菜不辣基的弱鸡开出的工资待遇要求,超过了我.不知道他们是怎么拿到那么高的工资的,难道是他在公司有亲戚朋友吗?有后台吗?是行业热钱真的过多了 ...
- 如何系统的学习Java
初学者记住一点,学习Java一定是连续性的且循序渐进的“系统化”学习,首先我给你提供一个优秀Java工程师的学习路线. web前端方面:html.css,Java.jQuery.xml解析.Boots ...
- python_练习04
选课系统 角色:学校.学员.课程.讲师 要求: 1.创建北京.上海2所学校 2.创建linux.python.go3个课程,linux.python在北京开,go在上海开3.课程包含,周期,价格,通过 ...
- css note
1.text-align规定了其子元素的对齐方式,当设置在子元素无效时,尝试设置在父元素,子元素可以水平居中: 2.vertical-align使用的前提,首先元素必须是display:inline ...
- 关于Eclipse for Python
学习Python一段时间,一直用Python的IDE进行开发,过程蛮顺利,但是,基于Visual Studio的使用经验,就希望尝试一种更友好的,更方便管理项目的IDE,分别尝试了PyCharm和Ec ...