I update a project to use Spring Boot 3.0.1 and hit a problem with SLF4j:
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.
...
IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.helpers.NOPLoggerFactory loaded from file
:/C:/Users/ruecker/.m2/repository/org/slf4j/slf4j-api/1.7.33/slf4j-api-1.7.33.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.helpers.NOPLoggerFactory
Investigating a bit I found that an old slf4j-api (1.7.x) was pulled in via json-path from spring-boot-starter-test, see mvn dependency:tree below.
Pom:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>3.0.1</version>
<scope>test</scope>
...
Dependencies:
O] +- org.springframework.boot:spring-boot-starter-test:jar:3.0.1:test
[INFO] | +- org.springframework.boot:spring-boot-test:jar:3.0.1:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:3.0.1:test
[INFO] | +- com.jayway.jsonpath:json-path:jar:2.7.0:test
[INFO] | | +- net.minidev:json-smart:jar:2.4.7:test
[INFO] | | | \- net.minidev:accessors-smart:jar:2.4.7:test
[INFO] | | | \- org.ow2.asm:asm:jar:9.1:test
[INFO] | | \- org.slf4j:slf4j-api:jar:1.7.33:compile
As a workaround I can add slf4j-api manually to my own project and it works:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.6</version>
</dependency>
The dependency should be fixed (or excluded?) in spring-boot-test-autoconfigure
Comment From: bclozel
This should be already supported if your application inherits from the Spring Boot parent or if it applies the Spring Boot dependency management.
Could you share a sample application reproducing the problem if it's not the case?
Comment From: berndruecker
Thanks @bclozel for the quick response! You are right about the parent or dependency management. This might reduce priority indeed (and explains why I haven't found much about this problem via Google).
Apparently I seldom use any of those possibilities (for the sake of using own parents, and the other one is quite intrusive if you "just" need one or two dependencies from Spring Boot) that's why it popped up. I think in this case slf4j-api could also be excluded in the json-path dependency within spring-boot-starter-test as it makes the setup more robust?
Comment From: bclozel
We can't exclude this dependency there as it is indeed a mandatory dependency for json-path; for this case, applying a BOM to a project (which is what spring-boot-dependencies is) guarantees a known set of compatible versions for your application. I'd suggest applying it to your application so it runs with the set of dependencies used in our test suite and by the community at large for the Spring Boot version you're using.
Thanks!