Web app root system property already set to different value

本文介绍了当两个基于Spring框架的应用程序在同一Tomcat容器中部署时出现“webAppRoot系统属性值冲突”的问题及解决方案。提供了三种解决办法:设置唯一的webAppRootKey参数值、禁用相对路径的日志文件配置或是移除Log4jConfigListener。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      标题中的错误提示是带有spring框架的多个项目部署后启动时出现的,在其他网站上找到一封英文回复,回答了这个解决问题的办法。括号中的文字为自己翻译的。

 

Hi all,

when deploying two applications build from the riot skeleton within 
the same Tomcat servlet container, you get an

IllegalStateException: Web app root system property already set to 
different value: 'webapp.root' = [/Users/joe/
Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/webapps/
webapp-A/] instead of [/Users/joe/Workspace/.metadata/.plugins/
org.eclipse.wst.server.core/tmp0/webapps/webapp-B/] - Choose unique 
values for the 'webAppRootKey' context-param in your web.xml files!(这是错误的具体提示信息)

I will try to explain where this comes from and how to circumvent it, 
but first the quick fix for the impatient reader: Place a context 
parameter named 'webAppRootKey' in every project's web.xml(将名称为'webAppRootKey'的参数在

每个项目的web.xml中都要放置 ) and assign 
a value to it, that is unique for every of your projects like the 
project name itself.

The webAppRootKey context parameter is introduced by Spring. Along 
with the WebAppRootListener it allows exposing the web applications 
root directory as a system property. The value of the context 
parameter 'webAppRootKey' names the system property to use. If the 
context parameter 'webAppRootKey' is not set in the application's 
web.xml, Spring chooses the default value 'app.root'. While some 
servlet containers like Resin do isolate each web application's 
system properties, others like Tomcat do not. And that's what the 
former mentioned IllegalStateException is telling us:  The system
property 'app.root' already contains the root directory of the first 
web application when Spring tries to assign the root directoty of the 
second application to it.

Ok, that's the background information. A deeper look into the web.xml 
tells us, that there ist no WebAppRootListener configured. Why does 
this initialisation take place anyway? The stack trace from the 
exception reveals the culprit: The Log4jConfigListener also tries to 
set the webAppRootKey, because this is an interesting mechanism for 
the Spring/Log4j integration. It allows log and config file locations 
relative to the web applications root directory. The 
Log4jConfigListener supports three init parameters at the servlet 
context level: 'log4jConifgLocation', 'log4jRefreshInterval' and 
'log4jExposeWebAppRoot'. See JavaDocs for more informations.

But, none of these parameters are set in the riot project skeleton's 
web.xml and none of the Log4jWebConfigureres features are used by the 
riot project skeleton. As long as you do stay with default log4j 
setup, the Log4jConfigListener is superflous.

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

(1) Provide any of your applications with a unique 'webAppRootKey'.

在你的不同项目的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.

What do you think is the best solution and should be incorporated 
into the riot skeleton project?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值