解決多重web應用中webapp. root重用的問題

來源:互聯網
上載者:User

標籤:ready   install   sdn   figure   conf   org   cat   color   oda   

http://blog.csdn.net/chenyongsuda/article/details/5589410

啟動Tomcat是報錯:

Web app root system property already set to different value: ‘webapp.root‘ = [E:\AIT\poscoGroup\web\] instead of [E:\AIT\TOMCAT-6.0\webapps\posco\] - Choose unique values for the ‘webAppRootKey‘

解決方案:

 

以下是轉帖:

由於懶惰想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項配置好,錯誤解決。

解決多重web應用中webapp. root重用的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.