废话不多,先上代码:
1,添加依赖
compile group: 'io.vertx',name: 'vertx-web',version: '3.4.2'
2,上代码
package com.my;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.Router;
public class VertxServer {
public static void main(String[] args) {
Vertx vertx = Vertx.vertx(new VertxOptions().setWorkerPoolSize(40));
HttpServer server = vertx.createHttpServer();
Router router = Router.router(vertx);
router.route().handler(context -> {
HttpServerResponse response = context.response();
response.putHeader("content-type", "text/plain");
response.end("Hello World from Vert.x-Web!");
});
server.requestHandler(router::accept).listen(9998);
}
}
3,启动

网友评论