1. 程式人生 > >Tomcat 遷移 至 weblogic部署war包,log4j問題 完整版

Tomcat 遷移 至 weblogic部署war包,log4j問題 完整版

一、異常場景:
    釋出war包到tomcat,jetty中正常部署,war包解壓後用weblogic部署正常,war包直接在weblogic上部署異常:
Cannot set web app root system property when WAR file is not expanded


啟用更改期間出錯, 有關詳細資訊, 請檢視日誌。


訊息圖示 - 錯誤 java.lang.IllegalArgumentException: Invalid 'log4jConfigLocation' parameter: 
class path resource [log4j.properties] cannot be resolved to absolute file path
 because it does not reside in the file system:zip:
/home/oracle/domain/servers/AdminServer/tmp/_WL_user/teenagers-report/9dj5sc/war/WEB-INF/lib/_wl_cls_gen.jar!/log4j.properties
訊息圖示 - 錯誤 Invalid 'log4jConfigLocation' parameter: class path resource [log4j.properties] 
cannot be resolved to absolute file path because it does not reside in the file system: 
zip:/home/oracle/domain/servers/AdminServer/tmp/_WL_user/teenagers-report/9dj5sc/war/WEB-INF/lib/_wl_cls_gen.jar!/log4j.properties
    web.xml配置以及log4j位置:
  <!-- 如果是部署到Weblogic 則需要註釋,因為Weblogic本身就支援log4J -->
   
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
  </context-param>
  <context-param>
    <param-name>log4jRefreshInterval</param-name>
    <param-value>6000</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>
  
二、原因蒐集:
weblogic自身對log4j支援,在war部署時候,與org.springframework.web.util.Log4jConfigListener衝突
解決方案如下:
第一步:註釋如下配置:
  <!-- 如果是部署到Weblogic 則需要註釋,因為Weblogic本身就支援log4J -->
  <!--  
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
  </context-param>
  <context-param>
    <param-name>log4jRefreshInterval</param-name>
    <param-value>6000</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>
  -->


第二步 在web-inf下面建一個名為:weblogic.xml的檔案,檔案內容如下:




<?xml version="1.0" encoding="UTF-8"?>


<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90">
    <session-descriptor>
        <cookie-path>/</cookie-path>
    </session-descriptor>    


    <jsp-descriptor>
        <keepgenerated>true</keepgenerated>
        <page-check-seconds>60</page-check-seconds>
        <precompile>true</precompile>
        <precompile-continue>true</precompile-continue>
    </jsp-descriptor>


    <container-descriptor>
        <optimistic-serialization>true</optimistic-serialization>        
        <prefer-web-inf-classes>false</prefer-web-inf-classes>
        <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
         <prefer-application-packages>  
           <package-name>org.slf4j</package-name>  
        </prefer-application-packages>  


    </container-descriptor>        
</weblogic-web-app>










參考文件1

參考文件2