问题描述:工程中增加log4j,输出系统运行日志到指定目录。部署工程war包时提示:
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
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 -->
<!-- 如果是部署到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的文件,文件内容如下:
<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 6.0//EN" "http://www.bea.com/servers/wls610/dtd/weblogi
c-web-jar.dtd">
<weblogic-web-app>
<context-root>/SpringJMS</context-root>
<session-descriptor>
<session-param>
<param-name>CookieName</param-name>
<param-value>PSESSIONIRMS</param-value>
</session-param>
</session-descriptor>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>
</weblogic-web-app>