Class Path Contains Multiple Slf4j Bindings



  1. Lf4j: Class Path Contains Multiple Slf4j Bindings
  • Status:Closed
  • Resolution: Not a bug
  • Fix Version/s: None
  • Labels:
  • Environment:

This is a result of defining an SLF4J binding in both your project's classpath (JDT.classpath file) and your MANIFEST.MF file. You should remove your SLF4J binding from your project's class path: YourProject → Properties → Java Build Path → Libraries Select the SLF4J Binding JAR and hit 'Remove'. Springboot项目跑起来后,一直报SLF4J包冲突,看着很烦。Connected to the target VM, address: '127.0.0.1:64448', transport: 'socket'SLF4J: Class path contains multiple SLF4J bindings.SLF4J: Found binding in jar:file.

Estou fazendo um programa em java usando Maven 3.6.3 JSF 2.2 e Jboos Junit 4.12 e hibernate

o meu programa rooda bem, só que ao usar o teste do Maven clean ele da este erro:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Desenvolvimento/IDE/eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in file:/C:/Desenvolvimento/IDE/eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.

Preciso do vosso apoio.

Lf4j: class path contains multiple slf4j bindings

Derito

Assignee:
SLF4J developers list
Reporter:
Hélder Costa
Slf4j
Votes:
0Vote for this issue
Watchers:
1Start watching this issue

在Spring Boot集成SLF4j和Log4j2,启动后报错:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/clcaza/jars/majing-admin.jar!/BOOT-INF/lib/log4j-slf4j-impl-2.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/clcaza/jars/majing-admin.jar!/BOOT-INF/lib/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread 'main' java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.apache.logging.slf4j.Log4jLoggerFactory loaded from jar:file:/home/clcaza/jars/majing-admin.jar!/BOOT-INF/lib/log4j-slf4j-impl-2.7.jar!/). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.apache.logging.slf4j.Log4jLoggerFactory

原因及解决

原因是在classpath里有多个SLF4J的绑定,SLF4J最终绑定了org.apache.logging.slf4j.Log4jLoggerFactory。这和Logback冲突导致异常。

Lf4j: Class Path Contains Multiple Slf4j Bindings

集成Log4j2推荐使用starter,它可以很好帮我们处理此冲突,Maven添加以下依赖,并且排除spring-boot-starter-logging