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

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

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

以我这个为例,就有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>

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

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

相关文章:

  • 2021-04-07
  • 2021-07-06
  • 2019-09-17
  • 2021-11-20
  • 2021-03-27
  • 2021-11-06
  • 2021-05-10
  • 2021-11-11
猜你喜欢
  • 2021-11-17
  • 2021-09-03
  • 2021-06-07
  • 2021-12-26
  • 2021-06-01
  • 2021-05-02
  • 2022-01-08
相关资源
相似解决方案