NoSuchMethod org.slf4j.spi.LocationAwareLogger 错误

NoSuchMethod org.slf4j.spi.LocationAwareLogger error

我遇到了 NoSuchMethod org.slf4j.spi.LocationAwareLogger 通过 cmd 输入 mvn clean test 命令后我的代码出现错误。

可能与 maven 依赖有关,但我无法弄清楚我应该在 pom 中准确安排的位置 xml。

 <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.30</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.25</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jdk14</artifactId>
    <version>1.7.25</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-nop</artifactId>
    <version>1.7.25</version>
    <scope>test</scope>
</dependency>

此外,我尝试使用 mvn dependency:tree 检查依赖树,但没有任何意义。

使用mvn dependency:tree 看看maven决定给你哪个版本的slf4j。如果它选择了错误的版本,您可以使用依赖管理部分来指定您想要的版本。并且您需要将 pom 排除项添加到您不使用的依赖项中。

此外,如果使用 Eclipse IDE,还有另一种修复方法,使用 SHIFT + CTRL + T 打开以下类型“SLF4JLocationAwareLog” 您应该能够找到相关的库等潜在的冲突。 切换到 pom.xml 的依赖关系树视图以了解要添加的排除项。