Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
834 views
in Technique[技术] by (71.8m points)

xml - WebApproot in Spring

I get this error message

[ SEVERE: 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' = [C:UsersjaanlaiDocumentsNetBeansProjectsabsSovellusuildweb] instead of [C:UsersAdministratorDocumentsNetBeansProjectskeycard2uildweb] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!

It's odd, because I don't have any webAppRootKey defined in my files. What is it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The webAppRootKey is a context parameter that Spring uses in a couple of places. In this case, it's being used by the Log4jWebConfigurer. It exposes the webapp root as a system property that can be used in log4j configuration files, something like this:

log4j.appender.testfile.File=${webapp.root}/WEB-INF/testlog.log 

You would use this if you, for some reason, wanted to locate your logs relative to your webapp root.

The problem that you're running into is that some containers (notably Tomcat) don't maintain a per-webapp mapping of system properties. When you don't specify a webAppRootKey, Spring defaults it to webapp.root. Since you're running two apps in the same container, the second app you're trying to start up sees that the webAppRootKey is already set (via the default), and throws an error. Otherwise, the webAppRootKey would be set incorrectly, and you could end up with logs from one webapp in another webapp.

You can specify a different webAppRootKey using context parameters in your web.xml like so:

<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>webapp.root.one</param-value>
</context-param>

And

log4j.appender.testfile.File=${webapp.root.one}/WEB-INF/testlog.log 

in your log4j. This should take care of the conflict.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...