I am using the below code to load the properties defined in the application. conf for all three different environments like a stage, dev, prod.
Object ConfigLoader.scala
object ConfigLoader extends Serializable with Loggable {
private var profile = "generic"
def setup(profile1: String): Unit = {
if (profile1 != null && profile1.nonEmpty) {
this.profile = profile1
}
}
def getProfile(): String = {
profile
}
lazy val conf = ConfigFactory.load()
lazy val ENVIRONMENT = conf.getString("environment.env")
//collection urls filename
lazy val COLLECTION_URLS_FILENAME = conf.getString("collection.filename")
//schema filename
lazy val post_asset_actuals_schema_filename = conf.getString("schema.post_asset_actuals_schema_filename")
lazy val put_asset_collection_schema_filename = conf.getString("schema.put_asset_collection_schema_filename")
Application.conf contains the below details.
environment {
env = "DEV"
}
collection {
filename = "collection_url.properties"
}
schema {
post_asset_actuals_schema_filename = "post_asset_actuals_schema.json"
put_asset_collection_schema_filename = "put_asset_collection_schema.json"
put_asset_rule_schema_filename = "put_asset_rule_schema.json"
put_asset_rule_subscribe_schema_filename = "put_asset_rule_subscribe_schema.json"
}
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'collection'
at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:124)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:147)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:159)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:164)
at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:206)
at com.x.y.draxcore.util.ConfigLoader$.COLLECTION_URLS_FILENAME$lzycompute(ConfigLoader.scala:55)
at com.x.y.draxcore.util.ConfigLoader$.COLLECTION_URLS_FILENAME(ConfigLoader.scala:55)
at com.x.y.draxws.service.route.AssetFilterRoute$.<init>(AssetFilterRoute.scala:42)
at com.x.y.draxws.service.route.AssetFilterRoute$.<clinit>(AssetFilterRoute.scala)

ConfigFactory.load()loads the config fromapplication.conffrom root. In your case, you need to load e.g. dev like this:ConfigFactory.load("dev/application.conf")