Log4j2 - java.lang.NoSuchMethodError: com.lmax.disruptor.dsl.Disruptor

问题

项目使用了log4j2,由于使用了全局异步打印日志的方式,还需要引入disruptor的依赖,最后使用的log4j2和disruptor的版本依赖如下:


    org.apache.logging.log4j
    log4j-core
    2.11.1



    com.lmax
    disruptor
    3.2.0

在项目最开始的地方(第一次使用到log4j2的logger之前),通过代码来启用全局异步打印日志:

// use asyncLogger for log4j2 framework
System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");

然而在启动项目后报错如下:

java.lang.NoSuchMethodError: com.lmax.disruptor.dsl.Disruptor.(Lcom/lmax/disruptor/EventFactory;ILjava/util/concurrent/ThreadFactory;Lcom/lmax/disruptor/dsl/ProducerType;Lcom/lmax/disruptor/WaitStrategy;)V
        at org.apache.logging.log4j.core.async.AsyncLoggerDisruptor.start(AsyncLoggerDisruptor.java:97)
        at org.apache.logging.log4j.core.async.AsyncLoggerContext.start(AsyncLoggerContext.java:75)
    at .......

解决方法

该问题是因为Disruptor的版本较低导致,将版本改用较新版本的即可:


    com.lmax
    disruptor
    3.4.2

转载于:https://www.cnblogs.com/yulinlewis/p/10211563.html

你可能感兴趣的:(Log4j2 - java.lang.NoSuchMethodError: com.lmax.disruptor.dsl.Disruptor)