最近在用maven整合SSH做个人主页时候,在eclipse里面使用tomcat7插件发布项目是没有问题的,但当打包成war之后,使用tomcat7单独发布项目,就出现了以下的错误.

严重: Context [/wangxin] startup failed due to previous errors
八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
严重: The web application [/wangxin] 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.
八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
严重: The web application [/wangxin] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
严重: The web application [/wangxin] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] but has failed to stop it. This is very likely to create a memory leak.
八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
严重: The web application [/wangxin] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] but has failed to stop it. This is very likely to create a memory leak.
八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
严重: The web application [/wangxin] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] but has failed to stop it. This is very likely to create a memory leak.
八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
严重: The web application [/wangxin] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak.

这个错误的意思是:在tomcat7启动时候,tomcat自带的一个内存检查的监听器发现,你的项目使用了一个数据库的连接池,并没有关闭的情况下,又去注册了一个连接池,为了保证内存不泄露,所以不允许你项目进行部署.

理论上,使用了SSH框架去整合了数据库,使用了jpa和c3P0连接池,是根本不需要去关心是要去关闭连接和GC的,但是还是报错,对此,就很有疑问了.

网上给出的理论是,因为tomcat7采用了一个监听技术,所以就会这样,完全可以关闭.但事实上,我关闭了之后,虽然启动不报错了,但是还是部署不了,日志里面还是这个错误.

同样的,网上还说了一个方法,就是把数据库的jar包放到tomcat的lib下面,我试了还是没用.

最后层层排查,发现,错误出现在了我的applicationContext.xml上,为了方便开发,我把applicationContext.xml里面的jdbc方面全部提取出来,放到了一个性的applicationContext-jdbc.xml文件里面,并且在总的xml里面使用了<import>标签去插入.

然后,我发现我的web.xml文件配置有点不同,即spring的监听器的classpath配置错误

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>

我在classpath那边配置多加了一个*这就导致了

正确的代码:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

由于多配了一个*,这就导致了当启动加载的时候,先加载了applicationContext-jdbc的内容,然后再加载applicationContext的内容,当加载appliactionContext的时候,再次去加载里面<import>标签导入的applicationContext-jdbc内容,这就造成了一次项目加载了两次数据库的连接池,因此造成了重复加载,项目无法启动的问题.

对于web.xml的配置,在这里我还得说一个非常骚气的问题.

不知先前什么情况,在WEF-INF下自动生成了一个classes文件夹,然后文件夹里面竟然多了一个applicationContext文件(理论上编译时候,生成到target里面的WEF-INF文件夹下),这就造成了,当修改resource里面的xml文件时候,没有修改到classes里面的文件,于是悲剧的一幕发生了:

使用SSH框架整合,使用SpringJPA整合的时候,写了一个action,action里面是使用的注解,注入的service,service里面用注解注入的dao,dao只写了一个接口,接口继承了JpaRepository.

使用junit直接调用service里面方法,能获取到数据库里面的数据,而使用tomcat运行的话,调用action获取不到数据.根本不报错,使用debug发现,运行过程中,并没有注入service以及dao.即都是null.

结果原因就是:在maven项目中的classes文件夹下面,自动将resource全部复制过来,而在mavenresource里面的配置文件是修改过的,这就导致了,junit和tomcat运行时候采用的applicationContext.xml文件不同,导致了这个错误.而同时,在web.xml中,配置spring的监听器使用的是

<param-value>classpath*:applicationContext.xml</param-value>

即加载所有classpath下面的xml文件,这就造成了一种情况,就是在junit时候能加载spring自动注入,而使用tomcat却加载不了,同时还不会报错....

就这两个关于web.xml的错误,与君共勉!

registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped.的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. [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 ...

  5. 解决: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" ...

  6. 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 ...

  7. 严重: 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 ...

  8. 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中引入了内存泄露侦测,对于垃圾回收不能处理的对像,它就会做日志. ...

  9. 解决 01-Jul-2016 10:49:05.875 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [ROOT] registered the JDBC driver [com.mysql.jdbc.D

    01-Jul-2016 10:49:05.875 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoade ...

随机推荐

  1. IE6支持兼容min-width、max-width CSS样式属性

    IE6支持兼容min-width.max-width CSS样式属性 让IE6支持max-width.IE6支持min-width样式 我们在写CSS的时候,常常会遇到让一个图片或一个布局不能超出设定 ...

  2. 安装CentOS版本的yum(转载)

    安装CentOS版本的yum 下载源:http://mirrors.163.com/centos/6/os/i386/Packages/ 材料准备: python-iniparse-0.3.1-2.1 ...

  3. CentOS下安装网卡驱动

    前言最近,一台机器从FreeBSD换为CentOS,一路安装顺利.完事之后发现,网卡没有启用,dmesg | grep eth 命令确定网卡没有驱动导致的.于是开始了一路艰辛的安装过程. 安装过程1. ...

  4. java服务端json结果集传值给前端的数据输出格式

    在服务端输出json数据时按照一定的格式输出时间字段,fastjson支持两种方式:1.使用JSON.toJSONStringWithDateFormat方法2.JSON.toJSONString方法 ...

  5. jquery checkbox选中

    楼主写的在1.6之前是没有问题的,jquery 1.6后就要这样写了,<input type='checkbox' id='cb'/> <script> //获取是否选中 va ...

  6. thinkphp相关功能整合系列

    thinkphp整合系列之短信验证码.订单通知 thinkphp整合系列之rbac的升级版auth权限管理系统demo thinkphp整合系列之阿里云oss thinkphp整合系列之phpmail ...

  7. Visual Studio Code调试node.js:无法在PATH上找到运行时的node

    首先,环境变量Path中加入nodejs的路径: 验证nodejs是否已经加入环境变量: 接着,重新启动Visual Studio Code, 试一下,是不是好了~   附录:Visual Studi ...

  8. SqlAlchemy使用详解

    python之sqlalchemy创建表的实例详解 通过sqlalchemy创建表需要三要素:引擎,基类,元素 from sqlalchemy import create_engine from sq ...

  9. AWS系列-创建AMI

    AMI创建 在XEN中pv是半虚拟化,hvm是全虚拟化,pv只能用于linux内核的系统,效率更高,hvm可以虚拟所有常见操作系统(可以使用 windows),理论效率比pv略低,另外,hvm需要cp ...

  10. tinker

    Ios前一段时间因为热更新被强制下架也算是最大闻了,但Android没关系,继续玩 首先tinker比Andfix好多了,版本现在都到1.7.11了,Andfix不支持yunos, 现在项目中没有用到 ...