Chris
Chris

Reputation: 1203

Maven and Spring - SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"

I'm building a new spring web application which uses maven for dependency management. I am trying to use slf4j-api and slf4j-simple. I added them to my pom file, but when I build I get the error

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.

Which is indicative of slf4j not having an implementation, however, slf4j-simple is include in my pom. Below is my 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>    

Below is my maven dependency tree:

[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

Any ideas on what could be wrong? Thanks.

Upvotes: 2

Views: 16337

Answers (5)

ankurrc
ankurrc

Reputation: 1112

I was suffering from a similar problem. And to make matters worse Hibernate was not showing the full stacktrace of the exception.

I was using Eclipse Luna and was working on a Maven project.

After reading various answers pertaining to above issue, nothing helped until I used: 'Slf4j Maven Plugin Log' :

"A SLF4J implementation which delegates to maven-plugin logging toolkit. Especially useful when maven-plugin dependencies use slf4j, cause their logs aren't available as maven-plugin logs."

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

Upvotes: 3

AllanT
AllanT

Reputation: 961

Found this earlier today in my search for an answer. It wasn't for a long time later that I finally the answer that worked for me. This was answered for me by Spring behind the scenes logging

The jist of it is to add the following to your pom.xml:

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

Upvotes: 1

Will
Will

Reputation: 8641

We had a similar problem with log4j jars.

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

Was added to the start script to enable this to be picked up first. Turns out we were inherting, another version of the jar from a parent module

Upvotes: 0

ramsinb
ramsinb

Reputation: 2005

I tried your exact POM in my environment and everything works fine - no errors. Which leads me to believe its your environment. Its definitely note the POM because your WAR file is getting created correctly. So some other things you can look at:

  1. Are you sure you don't have a different version of SLF4J on the classpath? Maven tends to just pick one when doing a build and therefore could cause problems.
  2. I haven't used Spring Tool Suite (STS) previously however perhaps that is causing your problem, have you tried running mvn clean package on the command line? I know I've seen issues around stuff like this previously in eclipse where we had another version of SLF4J on the classpath and mvn would fail while building in Eclipse.

Upvotes: 0

Related Questions