ClassCastException: org.slf4j.impl.Log4jLoggerAdapter cannot be cast to ch.qos.logback.classic.Logger

后端 未结 4 462
面向向阳花
面向向阳花 2020-12-19 00:02

I was following this answer in order to add a appender on runtime. Even though that works for the original poster, I get this exception in line Logger logger = (Logger

4条回答
  •  孤城傲影
    2020-12-19 00:19

    This looks like a symptom of having multiple versions of the same dependency (slf4j) in your classpath.

    Look in your logs for this message:

    SLF4J: Class path contains multiple SLF4J bindings.

    It will default to using the first slf4j reference it finds in the classpath. In the past, I've fixed this by moving my Logback dependencies (logback-classic and logback-core) to the top of the dependencies section of my Maven pom.xml file, which places them earlier in the classpath. That's a fragile solution, and it may not work depending on your application architecture. (e.g. if your startup project contains the conflicting dependency in its pom.xml, and you reference Logback through another project and its pom.xml)

提交回复
热议问题