Vertx入门篇-01 - Hello Vertx

原文链接: https://yq.aliyun.com/articles/685856

Hello Vert.x

1、添加POM相关依赖

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    8
                    8
                
            
        
    

    
        
            
                io.vertx
                vertx-stack-depchain
                3.6.2
                pom
                import
            
        
    

    
        
            io.vertx
            vertx-core
        
    

2、新建VertxHello1,启动一个HttpServer

public class VertxHello1 {
    public static void main(String[] args) {
        // 创建一个 Http Server
        Vertx.vertx().createHttpServer().requestHandler(request -> {
            request.response()
                    .putHeader("Content-Type", "text/plain")
                    .write("Hello Vert.x!")
                    .end();
        }).listen(8080, http -> {
            if (http.succeeded()) {
                System.out.println("HTTP server started on http://localhost:8080");
            }else {
                http.cause().printStackTrace();
            }
        });
    }
}

你可能感兴趣的:(Vertx入门篇-01 - Hello Vertx)