1. 程式人生 > >日誌jar包錯誤

日誌jar包錯誤

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.

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.

未能載入類org.slf4j.inst.StaticLoggerBinder,當org.slf4j.inst.StaticLoggerBinder類無法載入到記憶體中時,將報告此警告訊息。當在類路徑上找不到適當的SLF4J繫結時,就會發生這種情況。將slf4j-nop.jar slf4j-simple.jar、slf4j-log4j12.jar、slf4j-jdk14.jar或Logback-classic.jar放置在類路徑上應該可以解決這個問題。從1.6.0到SLF4J版本1.6,在沒有繫結的情況下,SLF4J將預設為無操作(NOP)記錄器實現。如果您負責打包應用程式,而不關心日誌記錄,那麼將slf4j-nop.jar放在應用程式的類路徑上將消除此警告訊息。注意,嵌入元件(如庫或框架)不應該宣告依賴於任何SLF4J繫結,而應該只依賴於slf4j-API。當庫宣告對SLF4J繫結的編譯時依賴時,它會將該繫結強加給終端使用者,從而否定SLF4J的目的。

事故原因:—

SLF4J API is designed to bind with one and only one underlying logging framework at a time. If more than one binding is present on the class path, SLF4J will emit a warning, listing the location of those bindings.

When multiple bindings are available on the class path, select one and only one binding you wish to use, and remove the other bindings. For example, if you have both slf4j-simple-1.8.0-beta2.jar and slf4j-nop-1.8.0-beta2.jar on the class path and you wish to use the nop (no-operation) binding, then remove slf4j-simple-1.8.0-beta2.jar from the class path.

The list of locations that SLF4J provides in this warning usually provides sufficient information to identify the dependency transitively pulling in an unwanted SLF4J binding into your project. In your project’s pom.xml file, exclude this SLF4J binding when declaring the unscrupulous dependency. For example, cassandra-all version 0.8.1 declares both log4j and slf4j-log4j12 as compile-time dependencies. Thus, when you include cassandra-all as a dependency in your project, the cassandra-all declaration will cause both slf4j-log4j12.jar and log4j.jar to be pulled in as dependencies. In case you do not wish to use log4j as the the SLF4J backend, you can instruct Maven to exclude these two artifacts as shown next:
SLF4JAPI被設計為一次繫結一個並且只有一個底層日誌框架。如果類路徑上存在多個繫結,SLF4J將發出警告,列出這些繫結的位置。當類路徑上有多個繫結可用時,選擇一個也是唯一一個要使用的繫結,然後刪除其他繫結。例如,如果類路徑上有slf4j-Simple-1.8.0-beta2.jar和slf4j-NOP-1.8.0-beta2.jar,並且希望使用NOP(無操作)繫結,那麼從類路徑中刪除slf4j-Simpl-1.8.0-beta2.jar。SLF4J在此警告中提供的位置列表通常提供足夠的資訊,以標識依賴關係,並將不需要的SLF4J繫結到您的專案中。在您的專案的put.xml檔案中,在宣告無良依賴時排除此SLF4J繫結。例如,Cassandra-All版本0.8.1宣告log4j和slf4j-log4j12都是編譯時依賴項。因此,當您將Cassandra-所有作為依賴項包含在您的專案中時,Cassandra-all宣告將導致slf4j-log4j12.jar和log4j.jar作為依賴項被牽扯進來。如果不希望使用log4j作為SLF4J後端,可以指示Maven排除這兩個工件,如下所示:

**解決辦法~~~~~~~~~~~~~~**
在pom.xml檔案中匯入以下jar包


org.apache.cassandra
cassandra-all
0.8.1

<exclusions>
  <exclusion> 
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
  </exclusion>
  <exclusion> 
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
  </exclusion>
</exclusions>