【logback】SLF4J: Failed to load class org.slf4j.impl.StaticLoggerBinder.

测试logback,出现了如下报错:

1
2
3
4
5
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Process finished with exit code 0

使用Maven构建的工程,logback的配置文件也都正常,但却报了上面的错误。
仔细察看一番,发现从Maven仓库复制依赖时把scope也给带上了,pom文件中的范围是test,而我的调用代码写在main函数中(非test范围),所以报错了。
解决办法:
将pom文件中的scope给注释掉,重新加载一下依赖就好。

1
2
3
4
5
6
7
8
9
10
11
12
13
<dependencies>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>