1:在src/conf目录下创建conf.json
1{ 2 "http.port" : 8082 3}
2:创建Verticle,
1config().getInteger("http.port", 8080),将会读取配置文件,是否有http.port,没有就使用8080作为默认, 2 3package verticleTest; 4 5import io.vertx.core.AbstractVerticle; 6import io.vertx.core.Future; 7 8public class ConfigVerticle extends AbstractVerticle{ 9 10 public void start(Future<Void> fut) { 11 vertx 12 .createHttpServer() 13 .requestHandler(r -> { 14 r.response().end("<h1>Hello from my first " + 15 "Vert.x 3 application</h1>"); 16 }) 17 .listen( 18 // Retrieve the port from the configuration, 19 // default to 8080. 20 config().getInteger("http.port", 8080), 21 result -> { 22 if (result.succeeded()) { 23 fut.complete(); 24 } else { 25 fut.fail(result.cause()); 26 } 27 } 28 ); 29 } 30}
3:打包,发布。使用 -conf 将配置文件读入。
D:\Android\workspace1\Ali>java -jar target/Ali-0.0.1-SNAPSHOT-fat.jar -conf src/main/conf/conf.json
4:访问localhost:8082
