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.InvocationTargetException
	at 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包,或 版本不对。

  • 结论:
    log4j2 AsyncLogger错误 NoClassDefFoundError: com/lmax/disruptor/EventFactory_第1张图片

3. 解决

  • 引入 disruptor jar 包, 3.4.4版本。
       
       <dependency>
           <groupId>org.springframework.bootgroupId>
           <artifactId>spring-boot-starter-log4j2artifactId>
       dependency>
       
       <dependency>
           <groupId>com.lmaxgroupId>
           <artifactId>disruptorartifactId>
           <version>3.4.4version>
       dependency>

log4j2 AsyncLogger错误 NoClassDefFoundError: com/lmax/disruptor/EventFactory_第2张图片

  • 结果: 问题解决, 没有异常了。

4. 资料

log4j2 Runtime Dependencies:https://logging.apache.org/log4j/2.x/log4j-core/dependencies.html

你可能感兴趣的:(Exception,log4j,asyncLogger)