Last Updated: February 25, 2016
·
1.766K
· raulraja

Play2! application.conf override based on environment

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.scala


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)
  }

}

application.conf


# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
application.global = com.company.Global