log4j 错误状态记录器无法为ctx创建查找

nafvub8i  于 2022-11-06  发布在  其他
关注(0)|答案(1)|浏览(1565)

我在运行项目时遇到此错误:

ERROR StatusLogger Unable to create Lookup for ctx

下面是整个堆栈跟踪:

ERROR StatusLogger Unable to create Lookup for ctx java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/ServiceLoaderUtil at org.apache.logging.log4j.core.impl.ThreadContextDataInjector.getServiceProviders(ThreadContextDataInjector.java:77) at org.apache.logging.log4j.core.impl.ThreadContextDataInjector.(ThreadContextDataInjector.java:64) at org.apache.logging.log4j.core.impl.ThreadContextDataInjector$ForCopyOnWriteThreadContextMap.(ThreadContextDataInjector.java:211) at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createDefaultInjector(ContextDataInjectorFactory.java:94) at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createInjector(ContextDataInjectorFactory.java:71) at org.apache.logging.log4j.core.lookup.ContextMapLookup.(ContextMapLookup.java:34) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at org.apache.logging.log4j.core.util.ReflectionUtil.instantiate(ReflectionUtil.java:189) at org.apache.logging.log4j.core.lookup.Interpolator.(Interpolator.java:81) at org.apache.logging.log4j.core.lookup.Interpolator.(Interpolator.java:100) at org.apache.logging.log4j.core.config.AbstractConfiguration.(AbstractConfiguration.java:135) at org.apache.logging.log4j.core.config.NullConfiguration.(NullConfiguration.java:32) at org.apache.logging.log4j.core.LoggerContext.(LoggerContext.java:74) at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:254) at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218) at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:136) at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123) at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47) at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196) at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599) at org.apache.poi.ooxml.POIXMLDocumentPart.(POIXMLDocumentPart.java:56) at CreateDocumentSimple.main(CreateDocumentSimple.java:88) Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.util.ServiceLoaderUtil at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 27 more Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.core.impl.ThreadContextDataInjector at org.apache.logging.log4j.core.impl.ThreadContextDataInjector$ForCopyOnWriteThreadContextMap.(ThreadContextDataInjector.java:211) at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createDefaultInjector(ContextDataInjectorFactory.java:94) at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createInjector(ContextDataInjectorFactory.java:71) at org.apache.logging.log4j.core.impl.ReusableLogEventFactory.(ReusableLogEventFactory.java:42) at org.apache.logging.log4j.core.config.LoggerConfig.(LoggerConfig.java:101) at org.apache.logging.log4j.core.config.AbstractConfiguration.(AbstractConfiguration.java:138) at org.apache.logging.log4j.core.config.NullConfiguration.(NullConfiguration.java:32) at org.apache.logging.log4j.core.LoggerContext.(LoggerContext.java:74) at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:254) at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218) at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:136) at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123) at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47) at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196) at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599) at org.apache.poi.ooxml.POIXMLDocumentPart.(POIXMLDocumentPart.java:56) at CreateDocumentSimple.main(CreateDocumentSimple.java:88)

我不知道这是从哪里来的,因为我不使用任何记录器在我的整个项目。如果你需要更多的信息,请随时问。
下面是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>TestPoi</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.2.2</version>

        </dependency>
   

    </dependencies>

</project>
2nc8po8w

2nc8po8w1#

将库log4j-api.jar添加到类路径中。
要使您的项目正常工作,您必须删除所有以log4j-1.x开头的jar。
我犯了同样的错误,因为当我下载log4j依赖包时,我不知道我需要哪些文件,所以我添加了所有的文件。但是这样做,不管出于什么原因,现在使用的是log4j 1而不是log4j 2。

相关问题