发布作者: Charlotte
百度收录: 正在检测是否收录...
作品采用: 《 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 》许可协议授权
项目中使用maven引入springboot依赖,同时也引入了log4j2作为日志输出,但是运行启动类时报错
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/.../logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/.../log4j-slf4j-impl-2.13.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
这表明项目中同时存在 Logback 和 Log4j2 两个日志实现,它们都试图绑定到 SLF4J,导致冲突。
这时我又想用自己引入的log4j2作为日志输出,那么可以在web依赖中移除掉其日志依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.4.2</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
刷新maven依赖,再启动项目,发现消失了!
—— 评论区 ——