出错原因: tomcat下面同时放了两个项目
启动时报错,结果是一个项目正常,一个项目不能正常启动
严重: The web application [/inventory] registered the JDBC driver [com.alibaba.druid.mock.MockDriver] but failed to unregister it when the web application was s
topped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
刚开始以为是数据库连接池的bug,不能同时有两个连接池名称相同。尝试修改连接池名称后依然不管用。
并更新连接池jar包到最新包1.1.9, 问题并没有解决
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.9</version>
</dependency>
无奈之下继续baidu, 发现一遍国外文章
To prevent a memory leak, the JDBC Driver has been forcibly unregistered
并尝试写一个监听器,在项目销毁时,释放jdbc链接。依然不管用。
继续查看报错日志
发现cartalina.out 里面只有这样一个错,但是没有详细的错误信息
One or more listeners failed to start. Full details will be found in the appropriate container log file
于是新增一个日志配置 logging.properties
handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
org.apache.juli.FileHandler.level = FINE
org.apache.juli.FileHandler.directory = ../logs
org.apache.juli.FileHandler.prefix = error-debug.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
然后会在logs文件下生成一个error-debug的文件查看里面错误信息
严重: Exception sending context initialized event to listener instance of class org.springframework.web.util.Log4jConfigListener
java.lang.IllegalStateException: Web app root system property already set to different value: 'webapp.root' = [D:\OPT\apache-tomcat-7.0.96-fh\webapps\fhm_weizu\] instead of [D:\OPT\apache-tomcat-7.0.96-fh\webapps\inventory\] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(WebUtils.java:163)
at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:119)
at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5197)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5720)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1707)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1697)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
于是顺藤摸瓜,在web.xml 中增加配置webAppRootKey后,完美解决
<context-param> <param-name>webAppRootKey</param-name> <param-value>webapp.inventory</param-value> </context-param>