检查是否没有application.conf

Check if there is no application.conf

如何检查我的 Spark 应用程序是否没有 application.conf?

我通过以下方式阅读了此会议:

Config configuracion = ConfigFactory.load();

但是当我检查时:

if (null != configuracion && !configuracion.isEmpty() && !configuracion.entrySet().isEmpty()){
    config_exists = true;
}

它总是 return config_exists=true.

谢谢!!

问题是 ConfigFactory.load() 加载了系统属性。因此生成的 Config 对象不为空。

我有一个技巧可以教给你,可能还有一个我不知道的更简单的方法。

Config conf = ConfigFactory.load();

// create a config containing only the system properties
Config emptyConfig = ConfigFactory.systemProperties();

// check that the loaded config is not equal to this "empty config"
Boolean isDefinedConfig = ! conf.equals(emptyConfig);