由于懒惰想copy一份工程来做测试用因此当AVerPortal 和AverPortalTest 都在tomcat的编译项目的时候会出现错误
2010-5-14 9:45:40 org.apache.catalina.core.StandardContext listenerStart
严重: 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' = [F:\JDKandTOMCAT\TOMCAT\Tomcat 6.0\webapps\AVerPortal\] instead of [F:\JDKandTOMCAT\TOMCAT\Tomcat 6.0\webapps\AVerPortalTest\] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
原因是当在web.xml中没指定
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>AVerPortalTest</param-value>
</context-param>
的时候按照默认的
做法1
在tomcatserver启动项目目录删除AVerPortal 和AverPortalTest 其中一个
做法2
在web.XML中添加webAppRootKey指定好
以下是转帖
近日,因为懒惰,直接从原有项目切出一个分块成了一个项目,然后同时发布启动,出现以下异常
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:\tomcat-5.0.19\webapps\tzbms\] instead of [D:\tomcat-5.0.19\webapps\its\] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(WebUtils.java:99)
at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:116)
at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:51)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3773)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4270)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:866)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:850)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:638)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:320)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:875)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:657)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:476)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1008)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:394)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:166)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1134)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:832)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1126)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:521)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2345)
at org.apache.catalina.startup.Catalina.start(Catalina.java:594)
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:324)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:297)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:398)
看看异常,还是挺简单的,应该是两个项目的设置重复了,导致出错,但我发现web.xml里并没有配置webAppRootKey项,然后查阅网上资料,参考
hwctl的专栏http://blog.csdn.net/hwctl/archive/2007/07/31/1719597.aspx
,原来是因为如果没有web.xm 内没有设置webAppRootKey项,是为默认设置
public static void setWebAppRootSystemProperty(ServletContext servletContext) throws IllegalStateException {
String param = servletContext.getInitParameter(WEB_APP_ROOT_KEY_PARAM);
String key = (param != null ? param : DEFAULT_WEB_APP_ROOT_KEY);
String oldValue = System .getProperty(key);
if (oldValue != null ) {
throw new IllegalStateException ("WARNING: Web app root system property already set: " + key + " = " +
oldValue + " - Choose unique webAppRootKey values in your web.xml files!" );
}
String root = servletContext.getRealPath("/" );
if (root == null ) {
throw new IllegalStateException ("Cannot set web app root system property when WAR file is not
expanded");
}
System .setProperty(key, root);
servletContext.log("Set web app root system property: " + key + " = " + root);
}
从代码看出,该方法其实就是把该web application的根目录的绝对文件路径作为属性保存在 System的属性列表中。该属性的名字,由web.xml文件中的名为"webAppRootKey"的参数值指出。如果不在web.xml中定义 webAppRootKey参数,那么属性名就是缺省的"webapp.root".在我们的petclinic项目中已经定义了 webAppRootKey参数,其值为"petclinic.root",因此,属性的名字就是"petclinic.root".
最后将webAppRootKey项配置好,错误解决。