score:15
Accepted answer
If your globals also need to be available to the methods in Global
, put them in Global.scala like so:
package object globals {
lazy val abc = Play.maybeApplication.flatMap(_.configuration.getString("abc")).getOrElse("default_value_of_abc")
lazy val someActor = Akka.system.actorOf(Props[SomeActor], name = "someActor")
}
And then use it in your controllers like this:
println(globals.abc)
globals.someActor ! SomeMessage
UPDATE
The documentation has since been updated how add Global.scala
in an idiomatic Play! way, with docs for both Scala and Java.
Source: stackoverflow.com
Related Query
- How to create a global variable with Play Framework 2.0
- How to create an instance of a model with the ebean framework and scala in Play 2.2
- How to create JSON output from a combined group of composite classes with Play framework
- How to create multiple users in play framework 2.5.x with WebSocket
- How can I create a submit button with parameter in the play framework
- How to use IntelliJ with Play Framework and Scala
- How to create a custom 404 page handler with Play 2.0?
- How to schedule an hourly job with Play Framework 2.1?
- How do I get Intellij IDEA 12.0 to work with Play Framework 2.1.0 app and Scala 2.10.0?
- How to print @ symbol in HTML with play framework (scala)
- How to run Play Framework 2.2.0 with -feature option
- How to set up play framework ApplicationLoader and Macwire to work with custom routes?
- How to call a template which accepts variable number of args in Play Framework 2
- How i can integrate Apache Spark with the Play Framework to display predictions in real time?
- How to tune Play Framework application with proper threadpools?
- How to use the Play Framework with Google App Engine with locally installed Java 7?
- how to create a List in play framework 2 scala templates
- Play framework JSON transformers, how to work with recursive paths (jsPath)?
- How to create a Play project with a specific version?
- How to create a data frame in a for loop with the variable that is iterating in loop
- How to use SORM framework with Play Framework?
- In a play framework config (hocon), how do I use an environment variable or a default?
- How to read and write Anorm object with the new JSON API in Play Framework 2.1-RC2?
- How can I create an infinite Enumerator with play iteratees
- With Scala 2.10.2, SBT 0.13.0, Specs2 & Play Framework 2.2.1 how can I control logging whilst running tests?
- How to create variable with the first day of current month in Databricks Spark Scala?
- How do I set up Play Framework 2.0 in Netbeans with Scala IDE
- Play Framework 2 - How to create a custom log file in scala
- How to create global Javascript variable in Scala js?
- How to create OFormat from Format in scala and play framework
More Query from same tag
- Change version in build.sbt custom task
- Why does Scala create a ~/tmp directory when I run a script?
- How to pickle in Client and Unpickle in Server?
- How to return a value to a val using if statement?
- how to append to a file using scala/breeze library
- SBT Project Publish to Maven Central
- How to Handle ValueError from Dataframe use Scala
- generic function to cast spark dataframe columns
- How to show difference between what is given and expected in ScalaTest?
- Disable the default logging of Akka ActorSystem
- Merging files by Partition
- Change the mapping of a field in Kibana from String to Double
- Can't get Play evolutions to work
- Adding immutable Vectors
- Iterating over a pair RDD to run a function on an RDD from the second value.
- Pattern matching in Scala and variables
- Scala project in Intellij
- saveToCassandra with spark-cassandra connector throws java.lang.ClassCastException
- Fill an area inside two CubicCurve2D.Float s and a line
- spark-scala checkpointing cleanup
- How to get an exploded version of "sbt universal:packageBin"?
- Checking attachments in the request
- Gatling rampUser and active user
- Using a conditional statement to send to different receiver actors
- Load a local file to spark using sc.textFile() using relative address?
- Difference between RoundRobinRouter and RoundRobinRoutinglogic
- How to force right resource file to be used when calling from another module
- Add custom BodyParser to non class Action
- SQL DDL metadata into Spark schema metadata
- List processing in DStream