gpt4 book ai didi

java - 关闭tomcat时Log4j中的这个异常是什么?

转载 作者:行者123 更新时间:2023-11-28 22:45:01 25 4
gpt4 key购买 nike

在 Web 应用程序中,我使用 log4j。
我使用了 shutdown Hook 来终止日志管理器:

Runtime.getRuntime().addShutdownHook(new Thread(){
@Override
public void run(){
LogManager.shutdown();
}
});

当 tomcat 关闭时,我在 catalina.out 中看到以下异常
这是什么意思?问题是什么,我该如何解决?

INFO: Illegal access: this web application instance has been stopped
already. Could not load org.apache.log4j.helpers.NullEnumeration.
The eventual following stack trace is caused by an error thrown for
debugging purposes as well as to attempt to terminate the thread which
caused the illegal access, and has no functional impact. Throwable
occurred: java.lang.IllegalStateException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1587)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
at org.apache.log4j.Category.getAllAppenders(Category.java:413)
at org.apache.log4j.Category.closeNestedAppenders(Category.java:226)
at org.apache.log4j.Hierarchy.shutdown(Hierarchy.java:467)
at org.apache.log4j.LogManager.shutdown(LogManager.java:267)
at com.MyLog4jStarter$1.run(Log4JStarterListener.java:133) Exception in thread "Thread-11" java.lang.NoClassDefFoundError:
org.apache.log4j.helpers.NullEnumeration
at org.apache.log4j.Category.getAllAppenders(Category.java:413)
at org.apache.log4j.Category.closeNestedAppenders(Category.java:226)
at org.apache.log4j.Hierarchy.shutdown(Hierarchy.java:467)
at org.apache.log4j.LogManager.shutdown(LogManager.java:267)
at de.siemens.icn.hipath.dls.listeners.Log4JInitListener$1.run(Log4JInitListener.java:42)
Caused by: java.lang.ClassNotFoundException:
org.apache.log4j.helpers.NullEnumeration
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)

最佳答案

异常的原因是一些类(例如NullEnumeration)已经被卸载。

向 webapp 添加钩子(Hook)的正确方法是实现 javax.servlet.ServletContextListener 并将此代码添加到 contextDestroyed 方法。您还必须在 web.xml 中注册您的监听器。

关于java - 关闭tomcat时Log4j中的这个异常是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9481264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com