java.lang.IllegalStateException: Web app root system property already set to different value...

java.lang.IllegalStateException: Web app root system property already set to different value: ‘webapp.root’ = [xxx]


Ref:http://stackoverflow.com/questions/5014651/webapproot-in-spring


Errors:

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' = [D:\N_Eclipse_32bit\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\GYMOBM\] instead of [D:\N_Eclipse_32bit\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\HNMOBM\] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
    at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(WebUtils.java:144)
    at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:117)
    at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:45)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Mar 27, 2017 1:22:28 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext

Solution:

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.


by Mike Sun; 2017-03-27

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值