试图启动Grizzly Server - 无法启动侦听器 - 已经在使用的地址

时间:2014-01-16 21:22:03

标签: java eclipse localhost httpserver grizzly

static HttpServer server;
static Datenbank  db = new Datenbank();

public static void main (String[] args) throws InterruptedException, IOException{

    startServer();
    db.dbinfo();
    Thread.sleep(10*60*1000);
    System.out.println("Server wurde beendet");
}

public static void startServer() throws IOException, InterruptedException {

    URI baseUri = UriBuilder.fromUri("http://localhost/").port(4434).build();

    ResourceConfig config = new ResourceConfig().register(BetroffenePersonenService.class);
    HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);

    try{
        server.start();
        NetworkListener listener = new NetworkListener("grizzly2","localhost", 4434);
        server.addListener(listener);
    }
    catch (Exception e){
        System.err.println(e);

    }
      }
     }

我正在尝试启动此服务器,但我一直得到这个

16.01.2014 22:04:31 org.lightcouch.CouchDbClientBase process
INFO: >> HEAD /betroffene HTTP/1.1
16.01.2014 22:04:31 org.lightcouch.CouchDbClientBase process
INFO: << Status: 200
16.01.2014 22:04:31 org.glassfish.jersey.server.ApplicationHandler initialize
INFO: Initiating Jersey application, version Jersey: 2.5 2013-12-18 14:27:29...
16.01.2014 22:04:32 org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [localhost:4434]
16.01.2014 22:04:32 org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
16.01.2014 22:04:32 org.glassfish.grizzly.http.server.HttpServer addListener
SCHWERWIEGEND: Failed to start listener [NetworkListener{name='grizzly2',     host='localhost',       port=4434, secure=false, state=STOPPED}] : java.net.BindException:   Address already in use
16.01.2014 22:04:32 org.glassfish.grizzly.http.server.HttpServer addListener
SCHWERWIEGEND: java.net.BindException: Address already in use
 java.net.BindException: Address already in use
at sun.nio.ch.Net.bind(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:124)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bindToChannelAndAddress(TCPNIOBindingHandler.java:132)
at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bind(TCPNIOBindingHandler.java:88)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:233)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:213)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:204)
at org.glassfish.grizzly.http.server.NetworkListener.start(NetworkListener.java:680)
at org.glassfish.grizzly.http.server.HttpServer.addListener(HttpServer.java:171)
at server.AbleServer.startServer(AbleServer.java:39)
at server.AbleServer.main(AbleServer.java:23)

我试图在网上找到解决方案,但我找不到任何适合我的方法。 我重新启动了所有内容,但它仍然说,该地址正在使用中。 它可能是一个非常小的错误导致所有这一切,但它确实让我感到沮丧。 你的帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

返回的服务器实例
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);

已经开始,所以你可以删除这些行:

server.start();
NetworkListener listener = new NetworkListener("grizzly2","localhost", 4434);
server.addListener(listener);