spring-boot + cloud log4j version compatibity issu

2019-08-16 19:29发布

问题:

I am developing an app in spring boot + gradle and using version 1.5.x version (tried 1.5.10, 1.5.2 and 1.5.1). The log4j version used by boot is 2.7

Everything works fine normally but I need to use a Socket Appender to send the logs to another host. This host uses log4j version 2.4

When I try to start my app I am getting the following error:

Caused by: java.lang.NoSuchMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/LoggerContext;Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration;

I have excluded the spring-starter-logging in gradle

configurations {
// Replace "spring-boot-starter-logging" with log4j
compile.exclude module: 'spring-boot-starter-logging'
compile.exclude group: 'log4j', module: 'log4j'
compile.exclude group: 'org.slf4j', module: 'slf4j-log4j12'
}

The exception I get on the server side with default log4j verison is:

2018-02-07 16:03:59,344 [ Thread-4] ERROR org.apache.logging.log4j.core.net.server.TcpSocketServer.9001 [] [env=;ses=;pag=;req=] - IOException encountered while reading from socket
java.io.InvalidClassException: org.apache.logging.log4j.core.impl.Log4jLogEvent$LogEventProxy; local class incompatible: stream classdesc serialVersionUID = -8634075037355293699, local class serialVersionUID = -7139032940312647146

If anyone has any clue it would be very helpful.