user6238728 user6238728 - 1 month ago 28
Java Question

MongoDB using Spark Java

When I run the code I'm getting the output as shown , how to fix this? thanks
Here I have used spark java

Mongodb
Intellij Idea
Should get Spark, Java, and MongoDB to work together

package com.mongodb;

import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;

/**
* Created by td on 10/20/2016.
*/
public class HelloWorldSparkStyle {
public static void main (String[] args){
Spark.get("/" ,new Route() {
public Object handle(Request request, Response response) throws Exception {
return "Hellow World from Spark";
}
});
}
}

[Thread-0] INFO org.eclipse.jetty.util.log - Logging initialized @1089ms
[Thread-0] INFO spark.embeddedserver.jetty.EmbeddedJettyServer - == Spark has ignited ...
[Thread-0] INFO spark.embeddedserver.jetty.EmbeddedJettyServer - >> Listening on 0.0.0.0:4567
[Thread-0] INFO org.eclipse.jetty.server.Server - jetty-9.3.6.v20151106
[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)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:326)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:244)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.server.Server.doStart(Server.java:384)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at spark.embeddedserver.jetty.EmbeddedJettyServer.ignite(EmbeddedJettyServer.java:128)
at spark.Service.lambda$init$0(Service.java:349)
at java.lang.Thread.run(Thread.java:745)

Process finished with exit code 100

Answer
java.net.BindException: Address already in use: bind

means that the port you start your web server on (4567) is already used by another process. Kill this process or use another port (ex: 8090 etc).

Comments