0

使用 slf4j.Marker 时出现 java.lang.IncompatibleClassChangeError。看来我在类路径中有几个 slf4j 版本。但是在执行 maven dependency:tree 时,它​​说只有 slf4j 1.7.25。你们有什么想法可能是什么问题吗?依赖关系如下:

  • 回退 1.2.3
  • slf4j 1.7.25
  • logstash-logback-encoder 5.0

该应用程序部署在 WildFlly 8.2.1 AS 上。

> -ERROR in net.logstash.logback.appender.LogstashTcpSocketAppender[stash] - Unable to process event: Class net.logstash.logback.marker.ObjectAppendingMarker does not implement the requested interface org.slf4j.Marker java.lang.IncompatibleClassChangeError: Class net.logstash.logback.marker.ObjectAppendingMarker does not implement the requested interface org.slf4j.Marker
> 
> 2018-03-31 00:17:03,287 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at java.lang.IncompatibleClassChangeError: Class net.logstash.logback.marker.ObjectAppendingMarker does not implement the requested interface org.slf4j.Marker
> 
> 2018-03-31 00:17:03,287 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.composite.loggingevent.JsonMessageJsonProvider.writeTo(JsonMessageJsonProvider.java:52)
> 
> 2018-03-31 00:17:03,287 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.composite.loggingevent.JsonMessageJsonProvider.writeTo(JsonMessageJsonProvider.java:31)
> 
> 2018-03-31 00:17:03,287 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.composite.JsonProviders.writeTo(JsonProviders.java:77)
> 
> 2018-03-31 00:17:03,287 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.composite.CompositeJsonFormatter.writeEventToGenerator(CompositeJsonFormatter.java:175)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.composite.CompositeJsonFormatter.writeEventToOutputStream(CompositeJsonFormatter.java:152)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.encoder.CompositeJsonEncoder.encode(CompositeJsonEncoder.java:114)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.encoder.CompositeJsonEncoder.encode(CompositeJsonEncoder.java:32)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.appender.AbstractLogstashTcpSocketAppender$TcpSendingEventHandler.onEvent(AbstractLogstashTcpSocketAppender.java:454)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.appender.AbstractLogstashTcpSocketAppender$TcpSendingEventHandler.onEvent(AbstractLogstashTcpSocketAppender.java:264)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.appender.AsyncDisruptorAppender$EventClearingEventHandler.onEvent(AsyncDisruptorAppender.java:330)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.appender.AsyncDisruptorAppender$EventClearingEventHandler.onEvent(AsyncDisruptorAppender.java:318)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2) 
4

1 回答 1

1

好吧,你是对的,因为类路径中有几个 slf4j 版本,所以会出现这个问题

现在我们需要找出它是如何发生的

情况1:

当我查看 maven repository 时,logback 1.2.3我发现它已经依赖于 slf4j。

所以当你加载 logback 1.2.3 时,slf4j 会自动添加

所以你不需要在 pom 中添加额外的 slf4j,如果你这样做,请删除它。

有关更多详细信息,请参阅链接- 编译依赖项:

案例二:

调查wildfly/modules/system/layers/base/org/slf4j

文件夹看看是否已经添加了任何 slf4j jars。如果是这样,您仅在编译时需要 slf4j

添加<scope>compile</scope>

于 2018-04-01T14:03:37.620 回答