Web app root system property already set to different value 的解決辦法

來源:互聯網
上載者:User

 

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 and assign   
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.rootalready 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'. 
(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?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.