I am not able to substitute the env variables in application.properties

maven dependency:


application.properties present in resources test=${FORCED_VARIABLE}


var config = ConfigFactory.load()



I am new to scala world, please suggest me what is that i am doing wrong

1 Answers

Chaitanya Waikar On

You need to provide your file name in configFactory.load() method

lazy val configFile = "application.properties"
lazy val config = ConfigFactory.load(configFile)
lazy val variableFromFile: String = config.getString("test")

If you see the documentation of ConfigFactory for load() method

 * Loads a default configuration, equivalent to {@link #load(Config)
 * load(defaultApplication())} in most cases. This configuration should be used by
 * libraries and frameworks unless an application provides a different one.
 * <p>
 * This method may return a cached singleton so will not see changes to
 * system properties or config files. (Use {@link #invalidateCaches()} to
 * force it to reload.)
 * @return configuration for an application
public static Config load() {
    ClassLoader loader = checkedContextClassLoader("load");
    return load(loader);

you will notice that load() method loads default configuration. Hope this helps !!!