我将log4j依赖项升级到最新的2.15.0版本,现在我的Spring应用程序在启动时抛出一个错误
Exception in thread "main" java.lang.NoSuchFieldError: EMPTY_BYTE_ARRAY
at org.apache.logging.log4j.core.config.ConfigurationSource.<clinit>(ConfigurationSource.java:56)
at org.apache.logging.log4j.core.config.NullConfiguration.<init>(NullConfiguration.java:32)
at org.apache.logging.log4j.core.LoggerContext.<clinit>(LoggerContext.java:85)
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:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at foo.bar.org.MyApp.<clinit>(MyApp.java:13)这是我的主修课
@Log4j2
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}发布于 2021-12-12 13:56:29
如果您的pom.xml中有以下内容:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.15.0</version>
</dependency>确保两者都有相同的版本。我忘记了其中一个(留下旧版本),并看到了同样的错误。
发布于 2021-12-13 03:02:18
<properties>
<log4j2.version>2.15.0</log4j2.version>
</properties><dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>发布于 2021-12-13 19:52:00
对我起作用的是排除log4japi和log4j核心的冲突版本的所有传递依赖项。
我追踪到他们:
mvn dependency:tree -Dverbose -Dincludes=org.apache.logging.log4j:log4j-api
和
mvn dependency:tree -Dverbose -Dincludes=org.apache.logging.log4j:log4j-core
因此,我确保2.15.0版本是整个项目中两个log4j依赖项的唯一版本。
https://stackoverflow.com/questions/70312144
复制相似问题