weblogic12c failed to load class org.slf4j.impl.StaticLoggerBinder

主要两个原因:

1 相关jar是否存在

2 各个jar的版本是否适当

3 各个jar之间是否存在冲突

 

日志相关jar示例:

<dependency>

    <groupId>log4j</groupId>

    <artifactId>log4j</artifactId>

    <version>1.2.17</version>

</dependency>

<dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>slf4j-log4j12</artifactId>

    <version>1.7.25</version>

</dependency>

<dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>slf4j-api</artifactId>

    <version>1.7.25</version>

</dependency>

 

若仍有问题,如在升级weblogic12c之后,因与weblogic12c自带slf4j冲突,以致加载失败。则可以在web-inf目录下的weblogic.xml文件中

  <container-descriptor>

    <prefer-web-inf-classes>false</prefer-web-inf-classes>

    <prefer-application-packages>

      <package-name>org.slf4j</package-name>

    </prefer-application-packages>

  </container-descriptor>

如此之后,可能在启动服务时仍报警告 failed to load class org.slf4j.impl……,但是看日志文件已经可以正常打印。

 

解释:

<prefer-web-inf-classes>false</prefer-web-inf-classes>  不会优先加载在web-inf下的jar

<package-name>org.slf4j</package-name>  指定只是slf4j优先加载应用程序或系统类中类

 

slf4j官方文档中说明:

Failed to load class org.slf4j.impl.StaticLoggerBinder

This warning message is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

Note that slf4j-api versions 2.0.x and later use the ServiceLoader mechanism. Backends such as logback 1.3 and later which target slf4j-api 2.x, do not ship with org.slf4j.impl.StaticLoggerBinder. If you place a logging backend which targets slf4j-api 2.0.x, you need slf4j-api-2.x.jar on the classpath. See also relevant faq entry.

since 1.6.0 As of SLF4J version 1.6, in the absence of a binding, SLF4J will default to a no-operation (NOP) logger implementation.

If you are responsible for packaging an application and do not care about logging, then placing slf4j-nop.jar on the class path of your application will get rid of this warning message. Note that embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J binding, it imposes that binding on the end-user, thus negating SLF4J's purpose.

大概意思总的来说,把slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar 或者logback-classic.jar中的一个且只能一个放到classpath中可能解决问题。

如果不关心日志,但是不想看到这个警告,可以加上slf4j-nop-x.x.x.jar。此处并没有说明jar冲突问题。

posted @ 2020-01-03 17:42  纵马天涯  阅读(488)  评论(0)    收藏  举报