Log4J配置错误 - 关于webapp.root的设置

  近日,因为懒惰,直接从原有项目切出一个分块成了一个项目,然后同时发布启动,出现以下异常

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项,是为默认设置




  1. public  static  void  setWebAppRootSystemProperty(ServletContext servletContext) throws  IllegalStateException  {
  2.         String  param = servletContext.getInitParameter(WEB_APP_ROOT_KEY_PARAM);
  3.         String  key = (param != null  ? param : DEFAULT_WEB_APP_ROOT_KEY);
  4.         String  oldValue = System .getProperty(key);
  5.         if  (oldValue != null ) {
  6.             throw  new  IllegalStateException ("WARNING: Web app root system property already set: "  + key + " = "  +
  7.                                                                 
  8.             oldValue + " - Choose unique webAppRootKey values in your web.xml files!" );
  9.         }
  10.         String  root = servletContext.getRealPath("/" );
  11.         if  (root == null ) {
  12.             throw  new  IllegalStateException ("Cannot set web app root system property when WAR file is not 
  13. expanded");
  14.         }
  15.         System .setProperty(key, root);
  16.         servletContext.log("Set web app root system property: "  + key + " = "  + root);
  17.     }




从代码看出,该方法其实就是把该web application的根目录的绝对文件路径作为属性保存在 System的属性列表中。该属性的名字,由web.xml文件中的名为"webAppRootKey"的参数值指出。如果不在web.xml中定义 webAppRootKey参数,那么属性名就是缺省的"webapp.root".在我们的petclinic项目中已经定义了 webAppRootKey参数,其值为"petclinic.root",因此,属性的名字就是"petclinic.root".

 

最后将webAppRootKey项配置好,错误解决。

你可能感兴趣的:(log4j,exception,Web,null,System,Class)