昨天项目 以2种方式进行跑,一种是 war包,一种是 文件夹的形式!
tomcat 下面2种方式都没问题。
weblogic下面 war包的形式进行部署的话 报如下错误:
Caused By: java.lang.IllegalStateException: Cannot set web app root system property when WAR file is not expanded
at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(WebUtils.java:139)
at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:118)
at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:47)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:481)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
Truncated. see log file for complete stacktrace
网上很多解决办法,说是 log4j 的配置问题,但是怎么搞都不行!
最后查看源码,发现其实主要问题是 : servletContext.getRealPath函数为空
然后就根据这个去查 ,发现果然是weblogic的问题;
解决办法:
在web-inf 下面 加 weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN" "http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">
<weblogic-web-app>
<container-descriptor>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>
</weblogic-web-app>
然后问题就解决了。
最近又遇到这个问题,发现另外一个新解决办法:
在web.xml 中配置 如下参数:
<context-param>
<param-name>log4jExposeWebAppRoot</param-name>
<param-value>false</param-value>
</context-param>
不过如果这样做的话 ,那么 log4j的配置文件 只能放在 class 下面 不能放在 web-inf 下面;
即 不能如此配置:
<!--启动LOG4J-->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
应该:
<!--启动LOG4J-->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
主要参考: http://wiki.bsdn.org/pages/viewpage.action?pageId=3440713