项目中引入了阿里的datahub依赖,测试时出现一下异常信息:
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/repository/ch/qos/logback/logback-classic/1.2.6/logback-classic-1.2.6.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/D:/repository/org/slf4j/slf4j-log4j12/1.7.32/slf4j-log4j12-1.7.32.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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
发现多个绑定:找到了logback-classic版本1.2.6和slf4j-log4j12版本1.7.32两个绑定。这两个绑定分别用于连接Logback和Log4j这两种不同的日志系统。
实际使用的绑定:尽管存在多个绑定,SLF4J会使用它首先找到的那个,这里就是ch.qos.logback.classic.util.ContextSelectorStaticBinder,意味着实际生效的日志框架是Logback。
解决问题:
1.查看这个依赖里面引入了那些日志框架依赖
2.查看项目中引入的依赖,是否是相同
3.自己项目中没有找到自己配置的和引进依赖里面的相同,那么就是,自己配置其他的依赖里面包含了相同的依赖
对于第3条,就可以选择移除多余的绑定,确保类路径中只保留一个SLF4J的绑定实现。既然实际上使用了Logback,应从项目中移除或排除对slf4j-log4j12依赖。
对于Maven项目,可以在依赖声明中添加排除语句
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
我这里移除了 logback-classic 日志实现,以便可以根据项目需求使用其他日志框架。