vertX 框架demo

1、pom.xml添加jar



    4.0.0

    com.qn
    Vert_X_Test
    1.0-SNAPSHOT

    
        UTF-8
        UTF-8
        1.8
        3.4.2
    

    
        
        
            io.vertx
            vertx-core
            ${vertx.version}
        
        
            io.vertx
            vertx-web
            ${vertx.version}
        

    

2、server类

package com.qn.server;

import io.vertx.core.AbstractVerticle;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;

/**
 * Created by win 10 on 2018/6/7.
 */
public class MyServer extends AbstractVerticle {

    @Override
    public void start() {

        Router router = Router.router(vertx);

        router.route().handler(this::queryHandler);
        vertx.createHttpServer().requestHandler(router::accept)
                .listen(8080);
        System.out.println("MyServer启动成功");
    }

    private void queryHandler(RoutingContext routingContext) {
        routingContext.response()
                .putHeader("content_type", "application/json")
                .end("hello world");
    }
}

3、启动类

package com.qn;

import com.qn.server.MyServer;
import io.vertx.core.Vertx;

/**
 * Created by win 10 on 2018/6/7.
 */
public class App {
    public static void main(String[] args) {
        Vertx vertx = Vertx.vertx();
        vertx.deployVerticle(MyServer.class.getName());
    }
}

你可能感兴趣的:(vertX)