Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar冲突问题

博客讲述了如何处理在项目中遇到的log4j-over-slf4j与slf4j-log4j12依赖冲突问题。通过IDEA的Maven Projects查看依赖层次,识别冲突源,然后排除不需要的依赖。文中以spring-boot-starter-web和slf4j-log4j12为例,说明排除冲突的方法,并指出即使有警告,但不影响运行的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先确定肯定是pom的依赖包冲突了,需要删一个,重点就是再哪儿去删掉,一个项目很多的依赖项的,怎么知道哪两个冲突呢?

这里介绍一种方法:用idea打开项目的,点击右边的 maven Projects,在dependencies里面就有很多的依赖项,而且是有层次的,那就找到含有我们的log4的依赖项。

以我这个为例,就有spring-boot-starter-web和另一个依赖slf4j-log4j12冲突,我这里需要的是自己依赖的log4j,而不是start内置的,所以排除starter的,代码:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

有些项目运行起来的时候会有这个警告,但是不影响运行,这里也是依赖多余了,但是这个没冲突,还能运行。

SLF4J: Found binding in [jar:file:/C:/Users/Administrator/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Administrator/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]

这里也一并处理掉:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

运行效果:然后文件也有了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值