发布于 4年前

解决SLF4J错误: Failed to load class "org.slf4j.impl.StaticLoggerBinder"

项目里使用slf4j作为日志的接口,报错如下:

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.

这个是没有绑定具体实现的logger,slf4j-api定义了日记操作的api,需要用户绑定具体的日志实现框架,如log4j。

解决方法:

绑定log4j添加类似的maven依赖。

<dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.5</version>
   </dependency>
   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
       <version>1.7.5</version>
   </dependency>

添加slf4j的简单实现类似

  <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.5</version>
   </dependency>
   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
       <version>1.6.4</version>
   </dependency>
©2020 edoou.com   京ICP备16001874号-3