侧边栏壁纸

关于Springboot日志冲突问题

2024年10月08日 142阅读 0评论 1点赞

项目中使用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依赖,再启动项目,发现消失了!

1
打赏

—— 评论区 ——

昵称
邮箱
网址
取消
人生倒计时
舔狗日记