美文网首页
Vert.x初探

Vert.x初探

作者: 田文健 | 来源:发表于2017-11-15 11:32 被阅读0次

    Vert.x是一个异步编程框架,支持多种语言编写。还能支持集群。
    用Java写的第一个HTTP请求服务。
    新建maven工程,把vert.x的依赖加进去:

      <dependency>
          <groupId>io.vertx</groupId>
          <artifactId>vertx-core</artifactId>
          <version>3.4.2</version>
        </dependency>
        <dependency>
          <groupId>io.vertx</groupId>
          <artifactId>vertx-web</artifactId>
          <version>3.4.2</version>
        </dependency>
    

    然后在main函数下写入下面的代码;

    Vertx vertx = Vertx.vertx();
            Router router = Router.router(vertx);
    
        
            HttpServerOptions options = new HttpServerOptions();
            vertx.createHttpServer(options).requestHandler(router::accept).listen(8080);
    
         
            router.route().path("/").handler(context -> {
                context.response().end("hello world");
            });
    
            System.out.println("已启动");
    

    启动程序,打开浏览器访问localhost:8080即可.

    相关文章

      网友评论

          本文标题:Vert.x初探

          本文链接:https://www.haomeiwen.com/subject/gongextx.html