1:在src/conf目录下创建conf.json

   

{
  "http.port" : 8082
}

2:创建Verticle,

 config().getInteger("http.port", 8080),将会读取配置文件,是否有http.port,没有就使用8080作为默认,

   

package verticleTest;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;

public class ConfigVerticle extends AbstractVerticle{

    public void start(Future<Void> fut) {
          vertx
              .createHttpServer()
              .requestHandler(r -> {
                r.response().end("<h1>Hello from my first " +
                    "Vert.x 3 application</h1>");
              })
              .listen(
                  // Retrieve the port from the configuration,
                  // default to 8080.
                  config().getInteger("http.port", 8080),
                  result -> {
                    if (result.succeeded()) {
                      fut.complete();
                    } else {
                      fut.fail(result.cause());
                    }
                  }
              );
        }
}

 

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

   vertx读取配置文件,获得端口号

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-06-16
  • 2021-08-16
猜你喜欢
  • 2022-12-23
  • 2021-04-01
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2022-01-15
相关资源
相似解决方案