Tomcat 迁移 至 weblogic部署war包,log4j问题 完整版

将Tomcat应用迁移到Weblogic时遇到log4j配置冲突问题,表现为WAR包直接部署报错,原因是Weblogic本身支持log4j与Spring的Log4jConfigListener冲突。解决办法包括:注释掉web.xml中的log4j相关配置,并创建weblogic.xml文件,设置特定参数来避免冲突。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、异常场景:
    发布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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值