log4j.xml ignores MDC keys - spring-boot

I have a Spring boot project with the following dependency:
[INFO] +- org.springframework.boot:spring-boot-starter-log4j:jar:1.3.8.RELEASE:compile
[INFO] | +- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] | +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] | +- org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] | \- log4j:log4j:jar:1.2.17:compile
And MDC usage:
import org.slf4j.MDC;
MDC.put("sheker", "kazav");
MDC.put("correlationId", "nonsense");
org.apache.log4j.Logger.getLogger(DEFAULT).info("the logger string");
In the log4j.xml I`m trying to print the Mapped Diagnostic Context keys as following:
<appender name="console" class="com.sheker.CustomConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%X{correlationId}] [%X{sheker}] - %m" />
</layout>
</appender>
I'm expecting to get:
[nonsense] [kazav] - the logger string
But the actual output is:
[] [] - the logger string
Why are the MDC keys get ignored?

the problem was:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/path/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/path/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
the solution is:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

if your class path contain multiple SLF4J bindings. then you can exclude others and keep only one binding. in springboot , other dependant jars could add slf4j or other logging frameworks to your project. run below maven command to find which jar is bringing these bindings and then exclude them from pom
mvn dependency:tree -Dincludes=:slf4j*
to exclude a jar from another dependancy add this to the dependancy
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>

Related

StackOverflowError when including Spring Boot Actuator as a dependency within the project

I'm currently running a Spring Cloud Streams project in version Greenwich.SR2. Just tried to include the following dependency within the project.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
But as soon as I include it and run the project, the following pops up.
SLF4J: Found binding in [jar:file:/Users/sample/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.2/log4j-slf4j-impl-2.11.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/sample/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.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.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread "main" java.lang.StackOverflowError
at org.apache.logging.log4j.util.StackLocator.getCallerClass(StackLocator.java:108)
at org.apache.logging.log4j.util.StackLocator.getCallerClass(StackLocator.java:121)
at org.apache.logging.log4j.util.StackLocatorUtil.getCallerClass(StackLocatorUtil.java:55)
at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:42)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
The set of dependencies regarding Spring Boot are the following ones.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
I already have .properties files for log4j2, is the Actuator dependency using older or any other version of the one which is already included?

Failed to load class “org.slf4j.impl.StaticLoggerBinder” error

I'm opening this post after I couldn't find a solution in the post:
Failed to load class "org.slf4j.impl.StaticLoggerBinder" error
I also opened a Maven project in IntelliJ and got the following error after choosing the option 'redeploy' in tomcat7 plugin:
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.
In the attached link, it was recommended to go to File-> Project Structure -> Artifacts and check for errors. This is what I see:
I also have the following dependencies in pom.xml file:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
Can you please help me finding the error?
Maybe there are two issues:
version mismatching of your dependencies
an issue when you deploy your application
For reproducing your error I've created this mini program:
package de.so;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DemoSlf4j
{
private static Logger logger = LoggerFactory.getLogger(DemoSlf4j.class);
public static void main(String[] args)
{
logger.error("Start ...");
}
}
with only these dependencies (same as you used) in pom.xml:
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
</dependencies>
I've got these messages:
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found
binding in
[jar:file:/D:/Maven-Repo/org/slf4j/slf4j-log4j12/1.5.6/slf4j-log4j12-1.5.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/D:/Maven-Repo/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.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.impl.Log4jLoggerFactory] SLF4J: The requested version 1.5.6
by your slf4j binding is not compatible with [1.6, 1.7] SLF4J: See
http://www.slf4j.org/codes.html#version_mismatch for further details.
log4j:WARN No appenders could be found for logger (de.so.DemoSlf4j).
log4j:WARN Please initialize the log4j system properly.
When I use these dependencies, everything is fine. Look at the versions!
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version> <!-- or use LATEST -->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version> <!-- or use LATEST -->
</dependency>
</dependencies>
If you are using org.slf4j:slf4j-log4j12:1.7.21 instead of slf4j-simple (what is more likely for production purposes), you'll get:
log4j:WARN No appenders could be found for logger (de.so.DemoSlf4j).
log4j:WARN Please initialize the log4j system properly. log4j:WARN See
http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
So do this:
look in your project dependencies if there are other artifacts which have cascading dependencies to logging frameworks (log4j, slf4f, ...).
check if your dependencies are proper deployed to your Tomcat. (.../WEB-INF/lib)
check the versions
Maybe you get cracked jar in your project ,check it in debug model detail,I had this problem too, when I build with debug model, I see warning of:
/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar ,so remove it ,and build it again. problem resolved.
You are providing a log api, and two different implementations, slf4j-log4j12 and slf4j-simple. I had the same issue, but in my case, it gave me an error message asking me to 'remove one' from class path.
You can try removing either slf4j-simple or slf4j-log4j12 from dependencies, clean and build project again.
I met with the same issue. I fixed it by adding the following dependencies to my POM.xml file:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
for the ${slf4j.version}, please assign the latest version number:
<properties>
...
<slf4j.version>1.7.30</slf4j.version>
</properties>

ERROR SLF4J: Class path contains multiple SLF4J bindings jenkins cobertura maven

I'm with this error on third day already and I can't resolved. There is something that I can't grasp on and no matter what I do the error still persists.
I'm reading a book called "Jenkins a definitive guide" (http://www.wakaleo.com/books/jenkins-the-definitive-guide) and I'm stuck on chapter two. Basically is a example of how to use Jenkins with Javadoc, JUnit and Cobertura plugin for Jenkins. Everything works until I get to Cobertura plugin part, where I get next error:
[ERROR] SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Windows/System32/config/systemprofile/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Windows/System32/config/systemprofile/.m2/repository/org/slf4j/slf4j-simple/1.6.1/slf4j-simple-1.6.1.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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
I have seen other problems like mine and the conclusion I got is that I have either to include o exclude a dependency in my pom.xml file/s (this examples only uses pom files at this stage). My pom.xml file that has slf4j-simple looks like this:
<project>
......
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
</project>
and there is no explicit dependency to logback-classic hence I don't know in what dependency is being used. I tried to use dependency plugin for jenkins and I got this result:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # gameoflife-web ---
[INFO] com.wakaleo.gameoflife:gameoflife-web:war:1.0-SNAPSHOT
[INFO] +- com.wakaleo.gameoflife:gameoflife-core:jar:1.0-SNAPSHOT:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.0.2.RELEASE:compile
[INFO] | +- org.springframework:spring-asm:jar:3.0.2.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:3.0.2.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:3.0.2.RELEASE:compile
[INFO] | | \- org.springframework:spring-aop:jar:3.0.2.RELEASE:compile
[INFO] | +- org.springframework:spring-context-support:jar:3.0.2.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:3.0.2.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:3.0.2.RELEASE:compile
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring-web:jar:3.0.2.RELEASE:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- org.mockito:mockito-all:jar:1.8.5:test
[INFO] +- org.easytesting:fest-assert:jar:1.4:compile
[INFO] | \- org.easytesting:fest-util:jar:1.1.6:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.6.1:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] \- org.hamcrest:hamcrest-all:jar:1.1:test
Maybe I'm blind, but I still can't see who uses logback-classic (by the way I'm not sure what values are correct for and for logback-classic).
I tried to remove the slf4j dependency's and I error is gone, but I don't get any cobertura reports. I tried to exclude logback-classic with
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
and the error persists.
I don't know what to do anymore, please help!
The good news is that even if SLF4J is reporting an error, it's actually warning you that SLF4J will be bound to ch.qos.logback.classic.util.ContextSelectorStaticBinder since there are two bindings available on the class path. SLF4J will pick the first one available on the class path. Your application should continue to work just fine albeit logging with logback.
I can't tell you why logback-classic.jar is on the class path but I suggest you investigate the "System profile" mentioned in the class path.
You are trying to exclude the logback-classic from the slf dependency itself. The issue is that as mentioned here, you were using more than one binding in your class path. Actual way is to keep exclusion for logback-classic, in the dependency which uses it and not in your slf4j dependency. Unfortunately, I am not sure which of your jars, are having a reference to slf4j which is causing the issue. One workaround is, use Ctrl+Sft+T to see the existence of the StaticLoggerBinder class, in different jars, and place the logback-classic exclusion in that. Other work around is, you can try keeping exclusion, as trial and error. These are just work arounds, but the concept is same. We need to find other dependency which has reference to logback-classic in your classpath
Please follow the below
Steps
Step1: Identify the classic logback using the mvn dependency:tree
Step2: Add the below exclusion in pom.xml
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
</exclusions>
Step3: Test the application
Credits go to the https://java2blog.com/fixed-slf4j-warning-class-path-contains-multiple-slf4j-bindings/

Prevent Flyway Maven Plugin from downloading old slf4j jars

When I run the flyway maven plugin it initially downloads the slf4j jars with a version of 1.5.6:
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/org/slf4j/slf4j-jdk14/1.5.6/slf4j-jdk14-1.5.6.pom
Downloaded: http://repo1.maven.org/maven2/org/slf4j/slf4j-jdk14/1.5.6/slf4j-jdk14-1.5.6.pom (2 KB at 21.3 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/slf4j/slf4j-parent/1.5.6/slf4j-parent-1.5.6.pom
Downloaded: http://repo1.maven.org/maven2/org/slf4j/slf4j-parent/1.5.6/slf4j-parent-1.5.6.pom (8 KB at 154.7 KB/sec)
This plays havoc with my Spring web app as I'm using version 1.7.2 of slf4j there and it gets confused when I restart it.
How can I prevent this? I've tried adding exclusions to my pom.xml:
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>2.0.3</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
but this still happens.
UPDATE: what this is causing is the following error when I build with Intellij 12:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/tom/Library/Caches/IntelliJIdea12/tomcat/Unnamed_incrowdnow/work/Catalina/localhost/_/WEB-INF/lib/slf4j-jdk14-1.5.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/tom/Library/Caches/IntelliJIdea12/tomcat/Unnamed_incrowdnow/work/Catalina/localhost/_/WEB-INF/lib/slf4j-simple-1.7.2.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.impl.JDK14LoggerFactory]
SLF4J: The requested version 1.5.6 by your slf4j binding is not compatible with [1.6, 1.7]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
UPDATE: output of
mvn dependency:tree -Dverbose -Dincludes=org.slf4j
[INFO] \- com.googlecode.flyway:flyway-maven-plugin:jar:2.0.3:compile
[INFO] \- org.apache.maven:maven-core:jar:2.2.1:compile
[INFO] +- org.apache.maven.wagon:wagon-webdav-jackrabbit:jar:1.0-beta-6:runtime
[INFO] | +- org.apache.jackrabbit:jackrabbit-webdav:jar:1.5.0:runtime
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.5.3:runtime - omitted for conflict with 1.7.2)
[INFO] | \- org.slf4j:slf4j-nop:jar:1.5.3:runtime
[INFO] | \- (org.slf4j:slf4j-api:jar:1.5.3:runtime - omitted for conflict with 1.7.2)
[INFO] +- org.slf4j:slf4j-jdk14:jar:1.5.6:runtime
[INFO] | \- (org.slf4j:slf4j-api:jar:1.5.6:runtime - omitted for conflict with 1.7.2)
[INFO] \- (org.slf4j:jcl-over-slf4j:jar:1.5.6:runtime - omitted for conflict with 1.7.2)
TIA,
Tom
Neither the Flyway Maven plugin 2.0.3, nor Flyway Core 2.0.3 depend on slf4j. Check your dependencies. The problem must be coming from somewhere else.
I had similar problem and solved it by using flyway-core dependency instead of flyway-maven-plugin dependency.
FLyway downloads slf4j dependencies, if your application uses 1.7.x or 1.6.x versions, then you will encounter this issue, since flyway downloads slf4j-nop of 1.5.3 version and slf4j-jdk14 of 1.5.6 version. In eclipse, you can see this under Dependency hierarchy of pom.xml
In order to get rid of this, add all the following exclusiions and you are done
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
</exclusions>

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.
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
Apparently this is a bug in the m2eclipse plugin.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". error
https://bugs.eclipse.org/bugs/show_bug.cgi?id=387064
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>
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:
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.
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.
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

Resources