我使用 Tomcat 10.0.6,log4j 2.14.1。當我關閉 Tomcat 時,我看到以下日志:
13-Nov-2021 22:32:32.915 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@59402b8f]) and a value of type [org.apache.logging.log4j.core.impl.MutableLogEvent] (value [org.apache.logging.log4j.core.impl.MutableLogEvent@7188af83]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Nov-2021 22:32:32.915 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@6be968ce]) and a value of type [org.apache.logging.log4j.core.pattern.DatePatternConverter.PatternFormatter] (value [org.apache.logging.log4j.core.pattern.DatePatternConverter$PatternFormatter@7c37508a]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Nov-2021 22:32:32.917 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@247310d0]) and a value of type [org.apache.logging.log4j.message.ReusableSimpleMessage] (value [org.apache.logging.log4j.message.ReusableSimpleMessage@1033576a]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Nov-2021 22:32:32.917 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@303cf2ba]) and a value of type [org.apache.logging.log4j.core.pattern.DatePatternConverter.PatternFormatter] (value [org.apache.logging.log4j.core.pattern.DatePatternConverter$PatternFormatter@76494737]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Nov-2021 22:32:32.921 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@59402b8f]) and a value of type [org.apache.logging.log4j.core.impl.MutableLogEvent] (value [org.apache.logging.log4j.core.impl.MutableLogEvent@17fc391b]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Nov-2021 22:32:32.921 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@6be968ce]) and a value of type [org.apache.logging.log4j.core.pattern.DatePatternConverter.PatternFormatter] (value [org.apache.logging.log4j.core.pattern.DatePatternConverter$PatternFormatter@2b30a42c]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
13-Nov-2021 22:32:32.926 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [airline] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@247310d0]) and a value of type [org.apache.logging.log4j.message.ReusableSimpleMessage] (value [org.apache.logging.log4j.message.ReusableSimpleMessage@609e8838]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
log4j2.xml
<Configuration>
<Properties>
<Property name="property_console">%d{HH:mm:ss} %-5level %logger{1} - %msg%n</Property>
<Property name="property_file">
%d{yyyy-MM-dd HH:mm:ss} %-5level [%t] %logger{6} - %msg%n
</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="${property_console}"/>
</Console>
<RollingFile name="FileRolling" fileName="logs/log.txt" append="true" filePattern="logs/${date:yyyy-MM-dd}/%d{yyyy-MM-dd_HH-mm}.txt">
<PatternLayout pattern="${property_file}"/>
<Policies>
<SizeBasedTriggeringPolicy size="100 K"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="ALL">
<AppenderRef ref="FileRolling"/>
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
我log4j2的pom.xml
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.14.1</version>
</dependency>
我認為這可能與我使用jakarta.servlet3.0 依賴項有關,但我不知道。將 .jar 移動到 tomcat/lib 不會發生任何變化。有什么問題?
uj5u.com熱心網友回復:
您的假設是正確的:log4j-web需要支持ServletContainerInitializers,這是在 Servlet 3.0 中引入的。
由于Servlet的5.0(是Tomcat 10實作),從改變類的全名javax.servlet.ServletContainerInitializer,以jakarta.servlet.ServletContainerInitializer因甲骨文和Eclipse基金會之間的著作權糾紛。因此,所有版本log4j-web都不適用于 Tomcat 10。
但是,您可以使用Jakarta EE的Tomcat 遷移工具來轉換所有Log4j 依賴項 jar。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/359086.html
上一篇:java.io.FileNotFoundException:/opt/tomcat/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.clas
