About vertx, java.net.BindException: Address already in use

Now, I begin to learn vert.x.

At first, I tried to define a function that can work.

However, my current implementation gives me the following error: when I run the program for the second time

 22, 2018 3:29:23  io.vertx.core.http.impl.HttpServerImpl
: java.net.BindException: Address already in use

I hope that when I run the second time, I can first detect the port, and if the port is occupied, close the port first

I could not find an answer from the documentation.

< H1 > Source code < / H1 >
package com.project.service;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.ext.web.Router;

import java.util.function.Consumer;

public class VerticleMain extends AbstractVerticle {


    @Override
    public void start() throws Exception {

        Router router = Router.router(vertx);

        router.route().handler(routingContext -> {
            routingContext.response()
                    .putHeader("content-type","text/html;charset=UTF-8")
                    .end("");
        });
        vertx.createHttpServer().requestHandler(router::accept).listen(8181);
    }

    public static void deployVertx() {
        String verticleId = VerticleMain.class.getName();
        VertxOptions options = new VertxOptions();
        Consumer<Vertx> runner = vertxStart -> {
            vertxStart.deployVerticle(verticleId);
        };
        Vertx vertx = Vertx.vertx(options);
        runner.accept(vertx);
    }

    public static void main(String[] args) {

        VerticleMain.deployVertx();
    }
}
Feb.28,2021

it seems that the port occupancy is turned off. It is to shut down the system process occupying the port.
you need to find out which process occupies the port first, and then in the kill process

in fact, you can just run the shutdown program for the first time. Wow, why bother?

Menu