Incerteza
Incerteza

Reputation: 34924

Checking a play current mode makes an error occur

I'm trying to get the current mode in Play application:

object Global extends GlobalSettings {
  val myVal = {
    val (a, b, c) = Play.current.mode match {
      case Mode.Dev | Mode.Test => ("a", "b", "c")
      case Mode.Prod => ("d", "e", "f")
    }

    new myClass(a, b, c)
   }
}

The error occurs in runtime saying Cannot initialize the custom Global object (%s) (perhaps it's a wrong reference?) and by stacktrace I can see it happens at val MyVal = {...

When I remove that field from Global then the error will disappear.

What's wrong with that?

Upvotes: 2

Views: 620

Answers (1)

biesior
biesior

Reputation: 55798

I hardly believe that you want to do something onStart or onStop, or maybe or some other event, but not just because ;)

object Global extends GlobalSettings {
  override def onStart(app: Application) {
    // put your code here....
  }
}

Upvotes: 3

Related Questions