Question
Log4j2 is used in the project. Due to the use of global asynchronous log printing, it is also necessary to introduce the dependency of disruptor. The version dependency of log4j2 and disruptor used last is as follows:
<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>
At the beginning of the project (before the logger of log4j2 is used for the first time), enable global asynchronous log printing through code:
// use asyncLogger for log4j2 framework
System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
However, the errors reported after starting the project are as follows:
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 .......
Solution:
The problem is caused by the lower version of the disruptor. Just change the version to the newer version:
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.4.2</version>
</dependency>
Read More:
- How to Fix log4j2 warning: warn unable to identify org.fusesource.jansi.WindowsAnsiOutputStream
- [Solved] Log4j2 log startup error: javax.xml.parsers.ParserConfigurationException…
- Split log by date in log4j2 of spring boot
- [2022 New Solution] SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder
- log4j:WARN Error during default initialization [How to Solve]
- [Solved] shiro Error: SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“.
- ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration…
- Spring Security Upgrade to Version 5.5.7, 5.6.4 or Above to Startup Error (Version incompatibility)
- How to Solve Swagger error: IllegalStateException
- How to Solve Spring integrate Seata startup error
- How to Solve Errors encountered by maven
- How to Solve Mybatisplusinterceptor error
- How to Solve EasyExcel3.0.5 Version Error
- How to Solve ERROR: Java 1.7 or later is required to run Apache Drill
- How to Solve Hbase JAVA import Package Error
- How to Solve JUnit Debugging initializationerror ERROR
- How to Solve idea com.baomidou Error
- How to Solve Error: Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.
- How to Solve Linux connecte to the old version of SQL Server Error
- How to Solve Error: Maven ‘parent.relativePath‘ of POM…