Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Spring Boot stops during startup inside its Logback logging setup

Your error

java.lang.IllegalStateException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation3 more lines it can show

Fix it fast

Most common cause, 1 of 3

A library brings a second SLF4J provider, and SLF4J binds to it

If you want Logback, exclude the extra provider from the dependency that drags it in.

Fix
<dependency>
  <groupId>com.example</groupId>
  <artifactId>library-that-brings-slf4j-simple</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
    </exclusion>
  </exclusions>
</dependency>
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath means SLF4J chose another backend, often Log4j 2 or slf4j-simple pulled in by a library, or a pinned slf4j-api 1.7 that cannot see Logback 1.3+. Keep exactly one SLF4J provider. Logback configuration error detected is different: Spring tags in logback.xml. Applies to Spring Boot 3.5 and 4.2.

  • Applies to Spring Boot 4.2.0 (Logback 1.6.6, SLF4J 2.0.20, Log4j 2.26.1), Spring Boot 3.5.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print every SLF4J, Logback and Log4j artifact in the build. Then read the brackets of the startup error: Spring Boot names the factory class SLF4J actually bound to and the jar it came from.

Run this first
mvn dependency:tree -Dincludes=org.slf4j,ch.qos.logback,org.apache.logging.log4j

Then find the line you see in this list and open its fix:

  1. 1A library brings a second SLF4J provider, and SLF4J binds to itThe brackets in the message name a factory outside ch.qos.logback, such as a Log4j or slf4j-simple class, and the tree shows that jar under some other dependency
  2. 2slf4j-api is held back at 1.7, which cannot find Logback 1.3 or newerThe tree shows org.slf4j:slf4j-api 1.7.x, startup prints SLF4J's Failed to load class org.slf4j.impl.StaticLoggerBinder warning, and the error names SLF4J's no-operation logger
  3. 3logback.xml uses springProfile or springPropertyThe exception reads Logback configuration error detected, and the lines under it point at a springProfile or springProperty element

What does the error look like?

  • java.lang.IllegalStateException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation
  • If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml
  • java.lang.IllegalStateException: Logback configuration error detected:
  • no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]

Cause 1 of 3

A library brings a second SLF4J provider, and SLF4J binds to it

You seeThe brackets in the message name a factory outside ch.qos.logback, such as a Log4j or slf4j-simple class, and the tree shows that jar under some other dependency

Check

Spring Boot's default starters log through Logback, and LogbackLoggingSystem refuses to start when SLF4J hands it any other factory. SLF4J binds to one backend only; with two on the classpath it warns and the pick is effectively random. A library that declares log4j-slf4j2-impl, slf4j-simple or slf4j-reload4j as a normal dependency is enough to cause it.

Check
mvn dependency:tree -Dincludes=org.slf4j:slf4j-simple,org.slf4j:slf4j-reload4j,org.apache.logging.log4j:log4j-slf4j2-impl

Fix

If you want Logback, exclude the extra provider from the dependency that drags it in. If you really want Log4j 2, do the opposite and follow Boot's how-to: exclude spring-boot-starter-logging and add spring-boot-starter-log4j2.

Fix
<dependency>
  <groupId>com.example</groupId>
  <artifactId>library-that-brings-slf4j-simple</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Verify

The tree shows logback-classic as the only SLF4J provider, and the application starts with Boot's normal console output.

Verify
mvn -q spring-boot:run

Confirmed by slf4j.org

Did this fix it?

Cause 2 of 3

slf4j-api is held back at 1.7, which cannot find Logback 1.3 or newer

You seeThe tree shows org.slf4j:slf4j-api 1.7.x, startup prints SLF4J's Failed to load class org.slf4j.impl.StaticLoggerBinder warning, and the error names SLF4J's no-operation logger

Check

SLF4J 2 finds providers with ServiceLoader, while 1.7 looked for org.slf4j.impl.StaticLoggerBinder. The SLF4J error page states that Logback 1.3 and later do not ship that class and need slf4j-api 2.x. Paired with 1.7, SLF4J falls back to its NOP logger, which Spring Boot then rejects as a non-Logback factory.

Check
mvn dependency:tree -Dincludes=org.slf4j:slf4j-api

Fix

Remove the hand-set slf4j-api version, or the older BOM that sets it, so the version managed by Spring Boot wins. Boot 4.2.0 manages slf4j-api 2.0.20 beside logback-classic 1.6.6.

Fix
<!-- delete from <dependencyManagement> or <dependencies> -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.36</version>
</dependency>

Verify

dependency:tree reports slf4j-api 2.0.x, the StaticLoggerBinder warning is gone, and the context starts.

Verify
mvn dependency:tree -Dincludes=org.slf4j:slf4j-api

Confirmed by slf4j.org

Did this fix it?

Cause 3 of 3

logback.xml uses springProfile or springProperty

You seeThe exception reads Logback configuration error detected, and the lines under it point at a springProfile or springProperty element

Check

Spring Boot's Logback extensions only work in logback-spring.xml or in a file named by logging.config, because the plain logback.xml is read before Spring is ready. Configuration scanning (scan="true") does not support the extensions either.

Check
grep -nE "springProfile|springProperty|scan=" src/main/resources/logback*.xml

Fix

Rename the file to logback-spring.xml so Spring Boot loads it after the environment exists, and remove scan="true" from the configuration element if the file uses the extensions.

Fix
git mv src/main/resources/logback.xml src/main/resources/logback-spring.xml

Verify

Start with a profile that a springProfile block targets; the block's settings apply and no configuration error is thrown.

Verify
mvn -q spring-boot:run -Dspring-boot.run.profiles=dev

Confirmed by docs.spring.io

Did this fix it?

How do I stop it coming back?

  • Let Spring Boot manage slf4j-api, logback-classic and the Log4j modules; never give them versions of your own.
  • Fail CI when the dependency tree contains a second SLF4J provider, using the same dependency:tree filter as the first step.
  • Name the Logback file logback-spring.xml from the start, even before it uses any Spring tags.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.