Java Intro to Java Web Development with Spark Diving into Web Development Meet Spark

I got an error! SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

I made sure the code was the exact same as the teacher had it. I can't figure out what I did wrong! :(

5 Answers

After a google search, I figured out that I needed to change compile 'com.sparkjava:spark-core:2.5' to compile 'com.sparkjava:spark-core:2.3'

To make it work for version 2.5, you can add the following dependency in build.gradle file.

compile 'ch.qos.logback:logback-classic:1.1.7'
Karrtik Iyer
Karrtik Iyer
3,738 Points

Yes, it worked for me after adding what harshahs has mentioned, but would want to understand why is it so? Isn't gradle supposed to download any transitive dependencies for spark-core, which would be logback-classic?

Blake Larson
Blake Larson
12,562 Points

I added that and still get the same error.

Alexander Nikiforov
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,139 Points

Hi, Blake Larson

Please check out my answer below :

Check out the Spark Documentation about this problem (Logging section) : http://sparkjava.com/documentation.html#examples There it says, how to deal with the problem very easily: to add slf4j-simple logging library dependencies. No need to go back to Spark 2.3 :)

So your build.gradle should look somewhat like this:

group 'com.teamtreehouse.courses'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {

    compile 'com.sparkjava:spark-core:2.5'

    // http://mvnrepository.com/artifact/org.slf4j/slf4j-simple
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'

    // optional can be removed
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

Why do I insist on solving the problem this way?

Because it is official Spark Documentation solution. Nothing personal

Alexander Nikiforov
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,139 Points

Check out the Spark Documentation about this problem (Logging section) : http://sparkjava.com/documentation.html#examples

There it says, how to deal with the problem very easily: to add slf4j-simple logging library dependencies.

No need to go back to Spark 2.3 :)

if you run into a binding error

[Thread-0] ERROR spark.embeddedserver.jetty.EmbeddedJettyServer - ignite failed java.net.BindException: Address already in use: bind at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:433) at sun.nio.ch.Net.bind(Net.java:425) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)

fireoff your task manager and check who is using port 4567

bascially, do this is a dos window netstat -anob | findstr "4567"

this will show you the process id

C:\WINDOWS\system32> netstat -anob | findstr "4567" TCP 0.0.0.0:4567 0.0.0.0:0 LISTENING 4184 TCP [::]:4567 [::]:0 LISTENING 4184

in my case PID is 4184

go to task manager and kill it.

then run your spark example

Chris Jones
Chris Jones
Java Web Development Techdegree Graduate 23,918 Points

Just FYI for anyone looking at Mark's answer above - you'll need to run the cmd prompt as an administrator. Just right click on the cmd prompt tool and choose "Run as Administrator".

Rares Conea
PRO
Rares Conea
Pro Student 14,998 Points

Hi, This question is old but if there is someone who still has this problem add before the get method this line: port(<a number that represent the port which you want to use>) Ex: port(8080)