web应用中webapp. root重用问题解决方案

 

同一个tomcat服务器里面部署两个JavaEE项目,都是用了log4j做日志。并且web.xml里面都监听了日志信息。

启动服务的时候报错。

于是在web.xml添加以下代码:

 

<display-name>myapp001</display-name>
	
	<context-param>
	    <param-name>webAppRootKey</param-name>
	    <param-value>myapp001.root</param-value>
	</context-param>
 

 

<display-name>myapp002</display-name>
	
	<context-param>
	    <param-name>webAppRootKey</param-name>
	    <param-value>myapp002.root</param-value>
	</context-param>
 

 

 

tomcat6中部署了两个web应用,都采用的是struts2+spring+hibernate框架,记录日志都用了log4j,结果webroot.app被重用了,启动tomcat时,出现错误,部分

错误信息如下:

严重: 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:\Program Files\tomcat6

\webapps\abc\] instead of [D:\Program Files\tomcat6\webapps\abc\] 

- Choose unique values for the 'webAppRootKey' context-param in your 

web.xml files!

 

 

 

At the end there are three possible solutions for the initial problem: 

(1) Provide any of your applications with a unique 'webAppRootKey'. 
(2) Set the servlet context parameter 'log4jExposeWebAppRoot' to   
'false'. This eliminates the use of log file locations relative to   
the web application's root directory but still allows a log4j config   
location outside the classpath. 
(3) Remove the 'Log4jConfigListener' from your application's web.xml. 

 

posted @ 2014-07-25 10:36  哈特中尉  阅读(1386)  评论(0编辑  收藏  举报