5

I am converting a spring app to spring-boot, using boot-starter-parent version: 2.0.4.RELEASE. When I build using mvn install, its is going through fine, but when I am trying to run the app using command:mvn spring-boot:run -Dspring.profiles.active=dev, I am getting this exception: ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder

Here are dependencies in my pom:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
</parent>

<dependencies>
  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-sleuth</artifactId>
    <version>2.0.1.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.24</version>
  </dependency>
  <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.3.0-alpha4</version>
  </dependency>
  <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>1.3.0-alpha4</version>
  </dependency>
</dependencies>

I have tried following the advice from this question, and using new and old versions of logback (both core and classic) dependencies, and adding the 'slf4j-log4j12' and 'slf4j-simple' but still getting the exception. Stack Trace is:

java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext (LogbackLoggingSystem.java:285) at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize (LogbackLoggingSystem.java:102) at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent (LoggingApplicationListener.java:191) at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent (LoggingApplicationListener.java:170) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener (SimpleApplicationEventMulticaster.java:167) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent (SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent (SimpleApplicationEventMulticaster.java:122) at org.springframework.boot.context.event.EventPublishingRunListener.starting (EventPublishingRunListener.java:68) at org.springframework.boot.SpringApplicationRunListeners.starting (SpringApplicationRunListeners.java:48) at org.springframework.boot.SpringApplication.run (SpringApplication.java:316) at org.springframework.boot.SpringApplication.run (SpringApplication.java:1258) at org.springframework.boot.SpringApplication.run (SpringApplication.java:1246) at com.hbo.esp.MyApplication.main (MyApplication.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)

1 Answer 1

7

Try changing version of each dependency as follow.

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.25</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.2.3</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>1.2.3</version>
</dependency>

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Had the same problem with SLF4J 1.8.0-beta4 and Logback 1.3.0-alpha4. But the above constelation works in my case, thanks! However I would appreciate an updated Logback (assuming the fault is there).
@phirzel, have you solved this issue for newer versions of Logback? I try to use it for Slf4j fluent API advantages, and have now error java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder on spring boot starting. Appreciates any help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.