crockpotveggies crockpotveggies - 1 year ago 125
Scala Question

Access Play! 2.0 configuration variables in application.conf?

Previously in Play! v1 it was really easy to define configuration variables in

and then access them like so:


However now I can't find anything in the documentation for similar uses in v2 or a proper alternative. What's the method for doing so? Thanks!

Answer Source

As of Play 2.5, play.api.Play.current is deprecated. You should use dependency injection to inject the Environment or Configuration and use that to read the configuration value:

class HomeController @Inject() (configuration: play.api.Configuration) extends Controller {
  def config = Action {

Checkout the Play documentation for more detailed discussion.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download