Skip to content

Instantly share code, notes, and snippets.

@raulraja
Created August 19, 2013 16:29
Show Gist options
  • Save raulraja/6271058 to your computer and use it in GitHub Desktop.
Save raulraja/6271058 to your computer and use it in GitHub Desktop.
Load application.conf overrides based on runtime environment and merge in overridden props. e.g. application.dev.conf, application.prod.conf, application.test.conf
...
# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
application.global = com.company.Global
...
package com.company
import play.api.{Mode, Configuration, GlobalSettings}
import java.io.File
import com.typesafe.config.ConfigFactory
object Global extends GlobalSettings {
override def onLoadConfig(config: Configuration, path: File, classloader: ClassLoader, mode: Mode.Mode): Configuration = {
println(s"loading config path: $path")
val configOverridePath = s"application.${mode.toString.toLowerCase}.conf"
val modeSpecificConfig = config ++ Configuration(ConfigFactory.load(configOverridePath))
println(s"merged config: $configOverridePath")
super.onLoadConfig(modeSpecificConfig, path, classloader, mode)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment