James
James

Reputation: 330

How would I resolve an slf4j logback classpath error in Java and Spring Boot?

So I'm currently using Twilio to send and receive text messages. I'm using Spring Boot for the framework of the application, Gradle as the build tool, and VSCode as the IDE.

It builds successfully when doing a bootRun, however my localhost server does not launch and causes the following exceptions in the DEBUG CONSOLE.

Below, I've put some parts of the Debug Console.

Multiple bindings

> Task :bootRun
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/james/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/1.7.21/be4b3c560a37e69b6c58278116740db28832232c/slf4j-simple-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/james/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/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.slf4j.impl.SimpleLoggerFactory]

Java IllegialArgumentException

Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.SimpleLoggerFactory loaded from file:/C:/Users/james/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/1.7.21/be4b3c560a37e69b6c58278116740db28832232c/slf4j-simple-1.7.21.jar).

Here are the implementation statements in my build.gradle file that are relevant to what I'm doing

implementation 'org.slf4j:slf4j-simple:1.7.21'
implementation 'com.sparkjava:spark-core:2.7.1'
implementation 'com.twilio.sdk:twilio:7.17.+'

Here are a few things that I have tried to solve the problem:

I've tried putting the following into my gradle file from another StackOverflow question

configurations.all {
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    exclude group: 'org.springframework.boot', module: 'logback-classic'
    exclude group: "org.slf4j"
}

Running bootRun at this point gives a build error and says that those packages don't exist

I've also tried reading through the URL in the DEBUG CONSOLE: http://www.slf4j.org/codes.html#multiple_bindings and I did not find anything useful for Gradle, as the solutions were only for Maven.

At this point I'm not sure what else to do.

Any ideas? Thanks in advance.

Upvotes: 0

Views: 2620

Answers (1)

Kedar Joshi
Kedar Joshi

Reputation: 1511

Spring Boot itself comes with a dependency on SLF4J and Logback as its implementation. You need to remove implementation 'org.slf4j:slf4j-simple:1.7.21' from your configuration.

Upvotes: 3

Related Questions