Unable to get any configuration readings outside the ".listen()" method

118 Views Asked by At

I am not able to get any configuration readings outside the ".listen()" method.

public class APIVerticle extends AbstractVerticle {

    @Override
    public void start(Future<Void> fut) {
            System.out.println("Config: " + config().getInteger("http.port")); //prints null

            vertx
                    .createHttpServer(serverOptions)
                    .requestHandler(router::accept)
                    .listen(
                            config().getInteger("http.port", 8080), //gets 8082
                            result -> {
                                if (result.succeeded()) {
                                    fut.complete();
                                } else {
                                    fut.fail(result.cause());
                                }
                            }
                    );
      }
}

my config file:

{
    "http.port": 8082
}

It gets packaged as a fat jar with maven-shade-plugin plugin.

Anybody an idea why?

1

There are 1 best solutions below

0
On BEST ANSWER

That's because your AbstractVerticle receives no deployment options. It was custom made. You can see example of how it's done in Starter class:

 String confArg = args.map.get("-conf");
    JsonObject conf;

    if (confArg != null) {
      try (Scanner scanner = new Scanner(new File(confArg)).useDelimiter("\\A")){
        String sconf = scanner.next();
        try {
          conf = new JsonObject(sconf);
        } catch (DecodeException e) {
          log.error("Configuration file " + sconf + " does not contain a valid JSON object");
          return;
        }
      } catch (FileNotFoundException e) {
        try {
          conf = new JsonObject(confArg);
        } catch (DecodeException e2) {
          log.error("-conf option does not point to a file and is not valid JSON: " + confArg);
          return;
        }
      }
    } else {
      conf = null;
    }

    ...
    deploymentOptions = new DeploymentOptions();
    deploymentOptions.setConfig(conf)

HttpServer receives those DeploymentOptions by default. If you have options to pass to your custom verticle, pass them as second parameter of .deployVerticle