奇忠诚 发表于 2017-2-18 09:22:58

Error: weblogic.management.DeploymentException: Cannot set web app root system p

  这2天要将项目以war包得形式发布到weblogic下面,在项目中用到了log4j初始化的的时候是用

<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
  来加载log4j的。但是发布到weblogc中报错了。

Error: weblogic.management.DeploymentException: Cannot set web app root system property when WAR file is not expanded - with nested exception.

  意思找不到那个log4j文件吧。在往上查了下,需要自己写个类加载下log4j文件

    package com.dep.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.servlet.http.HttpServlet;
import org.apache.log4j.PropertyConfigurator;
public class Log4jInit extends HttpServlet {
public void init() {
/**
* apache中的调用方法
* String prefix =getServletContext().getRealPath("/");
*
* String file = getInitParameter("log4j");
*// if the log4j-init-file is not set, then no point in trying
*
* System.out.println("................log4j start");
*
* if(file != null) {
*
* PropertyConfigurator.configure(prefix+file);
*}
*
*/
String file = getInitParameter("log4j");      
System.out.println("................log4j start");
if (file != null) {
Properties ps=new Properties();
try {
InputStream log = getServletContext().getResourceAsStream(file);
ps.load(log);
} catch (IOException e) {
e.printStackTrace();
}
PropertyConfigurator.configure(ps);
}
}
}

    <servlet>
<servlet-name>log4jLoader</servlet-name>
<servlet-class>com.dep.util.Log4jInit</servlet-class>
<init-param>
<param-name>log4j</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>

 
页: [1]
查看完整版本: Error: weblogic.management.DeploymentException: Cannot set web app root system p