【发布时间】:2022-01-15 14:19:02
【问题描述】:
我将 log4j 依赖升级到最新的 2.15.0 版本,现在我的 Spring Boot 应用程序在启动时抛出错误
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);
}
}
【问题讨论】:
-
你试过在这个类中使用这个日志来检查日志吗?
log.info("anything"); -
降级并与 Lombok 开发人员一起创建错误报告。
-
我非常怀疑这与龙目岛有什么关系。 Lombok 只生成一个 LogManager.getLogger 调用。这听起来像是您在依赖项堆栈中混合了版本。运行
java -jar lombok.jar delombok -p YourSourceFile.java然后尝试编译它,这将为您确认lombok 不是这里的问题。或者只是检查文档 -@Log4j2只是生成一个单行。 -
您是如何升级到 Log4j 2.15.0 的?
标签: java spring-boot lombok