User defined listener org.springframework.web.util.Log4jConfigListener failed: java.lang.IllegalStateException:
Cannot set web app root system property when WAR file is not expanded.
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:144)
at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:116)
at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:45)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:481)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) at .....看意思是说, war 档没有展开不能设置web 应用程序的系统属性。 错误出在WebUtils.java 的144行,
看一下144行的代码片段
public static void setWebAppRootSystemProperty(ServletContext servletContext)
throws IllegalStateException
{
Assert.notNull(servletContext, "ServletContext must not be null");
String root = servletContext.getRealPath("/");
if (root == null) {
throw new IllegalStateException("Cannot set web app root system property when WAR file is not expanded");
}
String param = servletContext.getInitParameter("webAppRootKey");
String key = (param != null) ? param : "webapp.root";
String oldValue = System.getProperty(key);
if ((oldValue != null) && (!(StringUtils.pathEquals(oldValue, root)))) {
throw new IllegalStateException("Web app root system property already set to different value: '" + key + "' = [" + oldValue + "] instead of [" + root + "] - " + "Choose unique values for the 'webAppRootKey' context-param in your web.xml files!");
}
System.setProperty(key, root);
servletContext.log("Set web app root system property: '" + key + "' = [" + root + "]");
}
的确,是会读取当前的servlet 的路径。 想想,weblogic 的确没有解压war档, 看来的确是找不到。
配置log4jExposeWebAppRoot 为false, 就不会去找这个路径了。修改web.xml,
<!-- begin for log4j -->
<context-param>
<param-name>log4jExposeWebAppRoot</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/config/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>6</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- end for log4j -->重新部署。 可以部署成功了, 但在weblogic控制台上回报一个找不到log4j.properties的错误, 没有解压,也就没有这个路径。
虽然, weblogic 不解压war 档,但是在 weblogic 的user_projects\domains\base_domain\servers\AdminServer\tmp\_WL_user 这个路径下, 会有web 项目的一些类型解压后的路径, 这应该是服务端缓存。
既然这样, 是否可以到这个路径下去找,把路径修改为: