2012-10-09 43 views
2

我正在構建一個新的使用maven進行依賴管理的spring web應用程序。我正在嘗試使用slf4j-api和slf4j-simple。我將他們添加到我的POM文件,但是當我建立我的錯誤Maven和Spring - SLF4J:無法加載類「org.slf4j.impl.StaticLoggerBinder」

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不具有實現,然而,SLF4J - 簡單就是包括我的聚甲醛。下面是我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>foo.bar</groupId> 
    <artifactId>name</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 
    <name>name</name> 


    <properties> 
     <org.springframework.version>3.1.0.RELEASE</org.springframework.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context</artifactId> 
      <version>${org.springframework.version}</version> 
      <exclusions> 
        <exclusion> 
         <groupId>commons-logging</groupId> 
         <artifactId>commons-logging</artifactId> 
        </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>${org.springframework.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>jstl</groupId> 
      <artifactId>jstl</artifactId> 
      <version>1.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
      <version>3.6.3.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>1.6.6</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-simple</artifactId> 
      <version>1.6.6</version> 
     </dependency> 
     <dependency> 
      <groupId>net.sourceforge.jtds</groupId> 
      <artifactId>jtds</artifactId> 
      <version>1.2.4</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <finalName>ROOT</finalName> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.5.1</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.1.1</version> 
       <configuration> 
        <packagingExcludes>WEB-INF/web.xml</packagingExcludes> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project>  

下面是我的Maven的依賴關係樹:

[INFO] foo.bar:name:war:0.0.1-SNAPSHOT 
[INFO] +- org.springframework:spring-context:jar:3.1.0.RELEASE:compile 
[INFO] | +- org.springframework:spring-aop:jar:3.1.0.RELEASE:compile 
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile 
[INFO] | +- org.springframework:spring-beans:jar:3.1.0.RELEASE:compile 
[INFO] | +- org.springframework:spring-core:jar:3.1.0.RELEASE:compile 
[INFO] | +- org.springframework:spring-expression:jar:3.1.0.RELEASE:compile 
[INFO] | \- org.springframework:spring-asm:jar:3.1.0.RELEASE:compile 
[INFO] +- org.springframework:spring-webmvc:jar:3.1.0.RELEASE:compile 
[INFO] | +- org.springframework:spring-context-support:jar:3.1.0.RELEASE:compile 
[INFO] | \- org.springframework:spring-web:jar:3.1.0.RELEASE:compile 
[INFO] +- jstl:jstl:jar:1.2:compile 
[INFO] +- org.hibernate:hibernate-core:jar:3.6.3.Final:compile 
[INFO] | +- antlr:antlr:jar:2.7.6:compile 
[INFO] | +- commons-collections:commons-collections:jar:3.1:compile 
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile 
[INFO] | +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile 
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile 
[INFO] | \- javax.transaction:jta:jar:1.1:compile 
[INFO] +- org.slf4j:slf4j-api:jar:1.6.6:compile 
[INFO] +- org.slf4j:slf4j-simple:jar:1.6.6:compile 
[INFO] \- net.sourceforge.jtds:jtds:jar:1.2.4:compile 

任何想法是什麼地方出錯了?謝謝。

+0

當您打開生成的WAR文件,看看裏面的'WEB-INF \ lib'目錄,你看,但SLF4J API和簡單(實現)?我問的原因是我想解決,如果你正在部署正確的WAR文件,或者你正在部署一個WAR文件,這是在添加SLF4J之前生成的簡單的實現... – ramsinb

+0

在戰爭中列出這兩個文件:slf4j-api-1.6.6.jar,slf4j-simple-1.6.6.jar – Chris

+0

你將部署什麼app/web服務器?它是應用程序的第一個類加載嗎?也許有關環境的細節......我不能立即看到任何問題與你在POM中擁有的一樣,它應該工作,除非你的app/web服務器或環境做了一些有趣的事情。 – ramsinb

回答

0

我在你的環境中試過你的確切POM,一切正常 - 沒有錯誤。這導致我相信它的環境。它肯定會記錄POM,因爲您的WAR文件已正確創建。所以你可以看一些其他的東西:

  1. 你確定你沒有在類路徑上有不同版本的SLF4J嗎? Maven在構建時往往會選擇一個,因此可能會導致問題。
  2. 我以前沒有使用過彈簧工具套件(STS),但是可能導致您的問題,您是否嘗試在命令行上運行mvn clean package?我知道我以前在eclipse中看到過類似這樣的問題,我們在類路徑中有另一個版本的SLF4J,而在Eclipse中構建時mvn會失敗。
+0

我試圖從命令行運行maven並沒有收到錯誤。此消息似乎是m2eclipse插件中的一個錯誤。謝謝你的幫助。 – Chris

0

我們有一個與log4j罐子類似的問題。

CLASSPATH="default/lib/log4j-1.2.16.jar" 
    CLASSPATH="$CLASSPATH:$JAVA_CLASSPATH:$APP_CLASSPATH" 

已添加到啓動腳本中,以便先啓用此選項。原來我們是在偷吃,從父模塊的另一個版本的jar

0

這個今天早些時候發現我在尋找一個答案。很長時間以後,我終於找到了適合我的答案。這是替我作了回答Spring behind the scenes logging

它的JIST是以下內容添加到您的pom.xml:

<dependency> 
<groupId>org.apache.logging.log4j</groupId> 
<artifactId>log4j-slf4j-impl</artifactId> 
<version>2.1</version> 
</dependency> 
3

我是從一個類似問題的痛苦。更糟糕的是,Hibernate沒有顯示異常的完整堆棧軌跡。

我在使用Eclipse Luna並且正在開發一個Maven項目。

閱讀有關上述問題的答案的各種後,沒有任何幫助,直到我用:「SLF4J Maven插件登錄」:

「A SLF4J實施委託給了Maven插件日誌記錄工具,該工具。特別有用當Maven的插件依賴性使用SLF4J,導致其日誌不能作爲Maven的插件日誌「

來源:http://mvnrepository.com/artifact/com.googlecode.slf4j-maven-plugin-log/slf4j-maven-plugin-log/1.0.0

+0

它的工作原理,謝謝! – PenguinEngineer

相關問題