Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder for jsonld example #66

Closed
wolfch-elsevier opened this issue Jan 26, 2024 · 2 comments

Comments

@wolfch-elsevier
Copy link

Upon running mvn spring-boot:run as advised in the subproject's README.md, Spring-Boot appears to start, then we 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.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
	at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:304)
	at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:118)
	at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:238)
	at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:220)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:178)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:171)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:145)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133)
	at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:79)
	at org.springframework.boot.SpringApplicationRunListeners.lambda$starting$0(SpringApplicationRunListeners.java:56)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
	at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:56)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:299)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1289)
	at cz.cvut.kbss.jopa.jsonld.JsonLdDemo.main(JsonLdDemo.java:27)
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)

I have never had advice suggested in the the URL https://www.slf4j.org/codes.html#StaticLoggerBinder to help. i.e. to push forward to to slf4j-2.0.x - rather, slf4j-1.3.x still works.

TL;DR

Looking at the jsonld subproject's pom.xml, I see there are no explicit dependencies declared for either slf4j or logback, which means this project is at the mercy of whatever transitive versions of those that are brought in by the direct dependencies. The output of mvn -U -Dmaven.test.skip=true -Dverbose -DoutputFile=deps.txt dependency:tree shows a lot of conflicting versions for slf4j but the final "winner" is 1.7.36 even though most of the dependency's transitive slf4j dependencies are trying for 2.0.6 or 2.0.7, however after the resolution, version 1.7.36 wins.

I tried forcing slf4j-2.0.7 as suggested in https://www.slf4j.org/codes.html#StaticLoggerBinder but kept getting the same ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder - this was not new to me; I have run into this many times. My solution is to downgrade logback to 1.2.x from 1.3.x.

Summary - the Fix

Explicitly use versions for slf4j, using 1.7.32 and logback 1.2.11.

@ledsoft
Copy link
Contributor

ledsoft commented Jan 26, 2024

Hi,
thanks for reporting this! It is actually not necessary to fix the version of SLF4J and logback in the jsonld sample project, as they are already inherited from the parent.
The problem is that I merged a GH dependabot PR which upgraded logback to 1.3 which is not supported by Spring Boot 2. Sorry for the confusion, that is totally on me, as it wasn't the first time I ran into this compatibility issue. I should have remembered that:)
I switched to logback 1.2.13 in the parent project and now it seems to work fine. I'll close this issue and your PR (which is totally fine, but I want the version fixed in the parent project).
Feel free to reopen or comment if you encounter any more problems.

@wolfch-elsevier
Copy link
Author

wolfch-elsevier commented Jan 26, 2024

Yep - works for me now, thanks! I forgot about inheritance from the parent pom.xml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants