我试图重现错误,而且我很难做到这一点。
基本上,我正在做的是:
我期待的是webapp在其日志中抛出NoClassDefFound
堆栈跟踪。
例如。
java.lang.NoClassDefFoundError: org/apache/log4j/DefaultThrowableRenderer
at org.apache.log4j.spi.ThrowableInformation.getThrowableStrRep(ThrowableInformation.java:87)
at org.apache.log4j.spi.LoggingEvent.getThrowableStrRep(LoggingEvent.java:413)
at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:313)
at org.apache.log4j.WriterAppender.append(WriterAppender.java:162)
at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
at org.apache.log4j.Category.callAppenders(Category.java:206)
at org.apache.log4j.Category.forcedLog(Category.java:391)
at org.apache.log4j.Category.log(Category.java:856)
at org.apache.commons.logging.impl.Log4JLogger.debug(Log4JLogger.java:166)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:989)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:183)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3717)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:176)
相反,发生的事情是webapp完成正常运行:
以下是代码:
@Controller
@Scope("session")
public class WeblogicFail {
private Logger logger = LoggerFactory
.getLogger(WeblogicFail.class);
public WeblogicFail()
{
}
@Autowired
AaBean ab;
@RequestMapping("/test")
@ResponseBody
public void submitQuery(HttpServletRequest request, HttpServletResponse res) throws IOException
{
request.getSession().setMaxInactiveInterval(15*60);
MyContainer mc = ab.someMethod();
logger.debug(mc.toString());
MyContainer mc2 = new MyContainer("aaaaa");
logger.debug(mc2.toString());
res.getOutputStream().write(("helloworld"+System.currentTimeMillis()).getBytes());
res.getOutputStream().flush();
res.getOutputStream().close();
}
}
@Component
public class AaBean {
private Logger logger = LoggerFactory.getLogger(AaBean.class);
public MyContainer someMethod()
{
logger.debug("some method start");
try {
Thread.sleep(1000*60*10); //1000 milliseconds is one second.
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
logger.debug("some method about to return");
return new MyContainer("here's a container");
}
}
public class MyContainer {
private String s;
public MyContainer(String s) {
super();
this.s = s;
}
@Override
public String toString()
{
return this.s + System.currentTimeMillis();
}
}
WeblogicFail-servlet.xml中:
<context:component-scan base-package="com.mytestspace" />
<context:annotation-config />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
记录器是:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
</dependency>
和Spring Framework是3.2.0.RELEASE
。
我在这里期待的是打印日志:
09:11:50 DEBUG AaBean:19 - some method start
09:21:50 DEBUG AaBean:27 - some method about to return
然后在域级别日志中获取堆栈跟踪。
相反,它继续执行正常,记录以下两个:
09:21:50 DEBUG WeblogicFail:62 - here's a container1437427310939
09:21:50 DEBUG WeblogicFail:65 - aaaaa1437427310939
并将正确的字符串返回给浏览器。
如果我删除了部署,它如何知道在哪里找到类定义等?
我已尝试强制进行垃圾回收as per here,但它仍继续成功运行。
这个问题与另一个问题不重复 - 因为这个问题是在删除部署时询问对象会发生什么。