Hello Vert.x
1、添加POM相关依赖
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-stack-depchain</artifactId>
<version>3.6.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
</dependency>
</dependencies>
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();
}
});
}
}