vert-x3 / vertx-zookeeper

Zookeeper based cluster manager implementation
Other
73 stars 67 forks source link

An error is reported when the "classpath:" prefix is added to the parameter #133

Closed wjw465150 closed 1 year ago

wjw465150 commented 1 year ago

Questions

when i use a custom configuration from the classpath

java -Dvertx.zookeeper.config=classpath:my/package/config/my-cluster-config.json -jar ... -cluster

Throw an exception:

16:10:38.059 [main] ERROR io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager - Could not find zookeeper config file
java.io.FileNotFoundException: chasspath:config\zookeeper-dev.json (文件名、目录名或卷标语法不正确。)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:195)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at java.io.FileInputStream.<init>(FileInputStream.java:93)
    at io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager.getConfigStream(ZookeeperClusterManager.java:144)
    at io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager.loadProperties(ZookeeperClusterManager.java:122)
    at io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager.<init>(ZookeeperClusterManager.java:97)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
    at java.util.Iterator.forEachRemaining(Iterator.java:116)
    at io.vertx.core.ServiceHelper.loadFactories(ServiceHelper.java:56)
    at io.vertx.core.ServiceHelper.loadFactories(ServiceHelper.java:42)
    at io.vertx.core.impl.VertxBuilder.init(VertxBuilder.java:270)
    at io.vertx.core.impl.launcher.commands.BareCommand.startVertx(BareCommand.java:224)
    at io.vertx.core.impl.launcher.commands.BareCommand.run(BareCommand.java:192)
    at io.vertx.core.impl.launcher.commands.RunCommand.run(RunCommand.java:246)
    at io.vertx.core.impl.launcher.VertxCommandLauncher.execute(VertxCommandLauncher.java:248)
    at io.vertx.core.impl.launcher.VertxCommandLauncher.dispatch(VertxCommandLauncher.java:383)
    at com.processon.vertx.IdeLauncher.main(IdeLauncher.java:12)

Version

io.vertx:vertx-zookeepe:4.3.8

screenshot

20230224161233 20230224161334

wjw465150 commented 1 year ago

i found The problem was found in the method"getConfigStream",this is i fixed code:

  private InputStream getConfigStream(String resourceLocation) throws FileNotFoundException {
    ClassLoader ctxClsLoader = Thread.currentThread().getContextClassLoader();
    InputStream is           = null;
    if (resourceLocation.startsWith("classpath:")) {
      resourceLocation = resourceLocation.substring(10);
      if (ctxClsLoader != null) {
        is = ctxClsLoader.getResourceAsStream(resourceLocation);
      }
      if (is == null && !resourceLocation.equals(CONFIG_FILE)) {
        is = new FileInputStream(resourceLocation);
      } else if (is == null && resourceLocation.equals(CONFIG_FILE)) {
        is = getClass().getClassLoader().getResourceAsStream(resourceLocation);
        if (is == null) {
          is = getClass().getClassLoader().getResourceAsStream(DEFAULT_CONFIG_FILE);
        }
      }
    } else {
      try {
        is = new FileInputStream(resourceLocation);
      } catch (FileNotFoundException fileEx) {
        if (ctxClsLoader != null) {
          is = ctxClsLoader.getResourceAsStream(resourceLocation);
        }
        if (is == null && resourceLocation.equals(CONFIG_FILE)) {
          is = getClass().getClassLoader().getResourceAsStream(resourceLocation);
          if (is == null) {
            is = getClass().getClassLoader().getResourceAsStream(DEFAULT_CONFIG_FILE);
          }
        }
      }

    }
    return is;
  }
wjw465150 commented 1 year ago

I have submitted a request on this issue: fix can not use a custom configuration from the classpath.