日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux slf4j找不到,SLF4J错误消息

發布時間:2024/9/19 linux 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux slf4j找不到,SLF4J错误消息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在本章中,我們將討論在使用SLF4J時獲得的各種錯誤消息或警告以及這些消息的原因/含義。

無法加載類“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.

要解決此問題,需要添加任一日志框架綁定。本教程上一小節對此進行了解釋說明。

注 - 這種情況發生在SLF4J的版本中,介于1.6.0和1.8.0-beta2之間。

No SLF4J providers were found

在slf4j-1.8.0-beta2中,上述警告更清楚地說“未找到SLF4J提供商”。

以下是完整的警告 -

SLF4J: No SLF4J providers were found.

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.

Classpath包含針對1.8之前的slf4j-api版本的SLF4J綁定

如果使用的是SLF4J 1.8版本,并且在類路徑中具有以前版本的綁定但沒有1.8的綁定,則會看到如下所示的警告。

SLF4J: No SLF4J providers were found.

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.

SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to

1.8.

SLF4J: Ignoring binding found at

[jar:file:/C:/Users/maxsu/Desktop/Latest%20Yiibai/SLF4J%20Tutorial/

slf4j-1.7.25/slf4j-jdk14-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#ignoredBindings for an explanation.

NoClassDefFoundError: org/apache/commons/logging/LogFactory

如果正在使用slf4j-jcl,并且類路徑中只有slf4j-jcl.jar,將得到一個例外(異常),例如下面給出的例外(異常)。

Exception in thread "main" java.lang.NoClassDefFoundError:

org/apache/commons/logging/LogFactory

at org.slf4j.impl.JCLLoggerFactory.getLogger(JCLLoggerFactory.java:77)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)

at SLF4JExample.main(SLF4JExample.java:8)

Caused by: java.lang.ClassNotFoundException:

org.apache.commons.logging.LogFactory

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

... 3 more

要解決此問題,需要將commons-logging.jar添加到類路徑中。

Detected both jcl-over-slf4j.jar AND bound slf4j-jcl.jar on the classpath..

綁定slf4j-jcl.jar將slf4j logger的調用重定向到JCL,jcl-over-slf4j.jar將JCL logger的調用重定向到slf4j。因此,不能在項目的類路徑中同時擁有這兩者。如果這樣做,會得到一個例外(異常),例如下面給出的(異常)。

SLF4J: Detected both jcl-over-slf4j.jar AND bound slf4j-jcl.jar on the class

path, preempting StackOverflowError.

SLF4J: See also http://www.slf4j.org/codes.html#jclDelegationLoop for more

details.

Exception in thread "main" java.lang.ExceptionInInitializerError

at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:71)

at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:42)

at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)

at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)

at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)

at SLF4JExample.main(SLF4JExample.java:8)

Caused by: java.lang.IllegalStateException: Detected both jcl-over-slf4j.jar

AND bound slf4j-jcl.jar on the class path, preempting StackOverflowError. See

also http://www.slf4j.org/codes.html#jclDelegationLoop for more details.

at org.slf4j.impl.JCLLoggerFactory.(JCLLoggerFactory.java:54)

... 7 more

要解決此問題,請刪除其中一個jar文件。

Detected logger name mismatch

可以通過以下方式創建Logger對象:

將要創建的記錄器的名稱作為參數傳遞給getLogger()方法。

將類作為參數傳遞給此方法。

如果通過將類作為參數傳遞來創建記錄器工廠對象,并且已將系統屬性slf4j.detectLoggerNameMismatch設置為true,那么作為參數傳遞給getLogger()方法的類的名稱和使用類應該相同,否則將收到以下警告 -

“Detected logger name mismatch”

請考慮以下示例。

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

public class SLF4JExample {

public static void main(String[] args) {

System.setProperty("slf4j.detectLoggerNameMismatch", "true");

//Creating the Logger object

Logger logger = LoggerFactory.getLogger(Sample.class);

//Logging the information

logger.info("Hi Welcome to Yiibai.com");

}

}

在這里,將slf4j.detectLoggerNameMismatch屬性設置為true。使用的類的名稱是SLF4JExample,傳遞給getLogger()方法的類名是Sample,因為它們都不相等,將會收到以下警告。

SLF4J: Detected logger name mismatch. Given name: "Sample"; computed name:

"SLF4JExample".

SLF4J: See http://www.slf4j.org/codes.html#loggerNameMismatch for an

explanation

Dec 10, 2019 10:23:00 PM SLF4JExample main

INFO: Hi Welcome to Yiibai.com

注 - 它在slf4j 1.7.9之后發生

Classpath contains multiple SLF4J bindings.

應該在類路徑中只有一個綁定。如果有多個綁定,將收到一個警告,列出綁定及其位置。

假設,如果在類路徑中有綁定slf4j-jdk14.jar和slf4j-nop.jar,將收到以下警告。

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in

[jar:file:/C:/Users/Yiibai/Desktop/Latest%20Yiibai/SLF4J%20Tutorial/

slf4j-1.7.25/slf4j-nop-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in

[jar:file:/C:/Users/Yiibai/Desktop/Latest%20Yiibai/SLF4J%20Tutorial/

slf4j-1.7.25/slf4j-jdk14-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an

explanation.

SLF4J: Actual binding is of type [org.slf4j.helpers.NOPLoggerFactory]

Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path

要將log4j logger調用重定向到slf4j,需要使用log4j-over-slf4j.jar綁定,如果要將slf4j調用重定向到log4j,則需要使用slf4j-log4j12.jar綁定。

因此,不能在類路徑中同時擁有這兩者。如果這樣做,將收到以下異常。

SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the

class path, preempting StackOverflowError.

SLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more

details.

Exception in thread "main" java.lang.ExceptionInInitializerError

at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:72)

at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:45)

at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)

at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)

at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)

at SLF4JExample.main(SLF4JExample.java:8)

Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar

AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.

See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.

¥ 我要打賞

糾錯/補充

收藏

加QQ群啦,易百教程官方技術學習群

注意:建議每個人選自己的技術方向加群,同一個QQ最多限加 3 個群。

總結

以上是生活随笔為你收集整理的linux slf4j找不到,SLF4J错误消息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。