码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-01-02 23:30:08      阅读:610      评论:0      收藏:0      [点我收藏+]

标签:...   its   str   log4   system   work   contexts   新版   strategy   

问题

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

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.11.1</version>
</dependency>
<!-- log4j2 AsyncLogger need disruptor-->
<dependency>
    <groupId>com.lmax</groupId>
    <artifactId>disruptor</artifactId>
    <version>3.2.0</version>
</dependency>

在项目最开始的地方(第一次使用到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.<init>(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的版本较低导致,将版本改用较新版本的即可:

<dependency>
    <groupId>com.lmax</groupId>
    <artifactId>disruptor</artifactId>
    <version>3.4.2</version>
</dependency>

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

标签:...   its   str   log4   system   work   contexts   新版   strategy   

原文地址:https://www.cnblogs.com/yulinlewis/p/10211563.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!