本文主要是介绍log4j2 AsyncLogger错误 NoClassDefFoundError: com/lmax/disruptor/EventFactory,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1. 描述
log4j2 配置AsyncLogger后,启动项目报错。
main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.async.AsyncLoggerConfig for element AsyncLogger: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: com/lmax/disruptor/EventFactory java.lang.reflect.InvocationTargetException。
- 配置:
<AsyncLogger name="com.demo" level="DEBUG" includeLocation="true"><AppenderRef ref="FILE_INFO"/><AppenderRef ref="FILE_ERROR"/></AsyncLogger>
- 环境
IDE: 2021.3
spring boot: 2.5.6 (spring-boot-starter-log4j2: 2.5.6 --- log4j-core: 2.14.1)
2. 问题
- Caused by: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: com/lmax/disruptor/EventFactory
2022-03-18 18:57:40,131 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.async.AsyncLoggerConfig for element AsyncLogger: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: com/lmax/disruptor/EventFactory java.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)-----------------
Caused by: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: com/lmax/disruptor/EventFactory
-
原因: 找不到这个类,com/lmax/disruptor/EventFactory。
-
猜想: 没有相关依赖jar包,或 版本不对。
-
结论:
3. 解决
- 引入 disruptor jar 包, 3.4.4版本。
<!-- 引入log4j2依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-log4j2</artifactId></dependency><!-- Required for AsyncLoggers --><dependency><groupId>com.lmax</groupId><artifactId>disruptor</artifactId><version>3.4.4</version></dependency>
- 结果: 问题解决, 没有异常了。
4. 资料
log4j2 Runtime Dependencies:https://logging.apache.org/log4j/2.x/log4j-core/dependencies.html
这篇关于log4j2 AsyncLogger错误 NoClassDefFoundError: com/lmax/disruptor/EventFactory的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!