Georg Heiler
Georg Heiler

Reputation: 17676

Play framework implicit application in scope

I just got started using sbt-multi projects. However I am running into problems with:

Application.scala:16: You do not have an implicit Application in scope. If you want to bring the current running Application into context, just add import play.api.Play.current

This line contains: if (Play.isDev) { and can be seen here: https://github.com/dataplayground/twitterPipeline/blob/master/modules/frontend/app/controllers/Application.scala

The problem is: even if I do import it there ist still a new error telling me that Play could not be found.

Context: I want to set up a simple web-socket using angular.

edit:

Hi, Thanks a lot. This partly seems to work. However I do need this variable in other methods as well. If I add it into the whole scope of the class I get the following error

Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.$conforms()Lscala/Predef$$less$colon$less;
[error]     at play.core.server.ServerStartException.<init>(ServerStartException.scala:10)
[error]     at play.core.server.ProdServerStart$.createPidFile(ProdServerStart.scala:127)
[error]     at play.core.server.ProdServerStart$.start(ProdServerStart.scala:45)
[error]     at play.core.server.ProdServerStart$.main(ProdServerStart.scala:27)
[error]     at play.core.server.ProdServerStart.main(ProdServerStart.scala)
java.lang.RuntimeException: Nonzero exit code returned from runner: 1
    at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last twitterPipeline/compile:run for the full output.
[error] (twitterPipeline/compile:run) Nonzero exit code returned from runner: 1. 

If I try to add it to a second method manually like

def socket = WebSocket.acceptWithActor[String, String] {
    implicit val app = play.api.Play.current
    request => out =>
    AnalysisActor.props(out)
  }

I receive the error from above.

Upvotes: 0

Views: 1452

Answers (1)

Johny T Koshy
Johny T Koshy

Reputation: 3887

You need Application in implicit scope. Following will work.

class Application extends Controller {
  implicit val app = play.api.Play.current

  def index = Action {
    val javascripts = {
      if (Play.isDev) {
        // Load all .js and .coffeescript files within app/assets
        Option(Play.getFile("app/assets")).
          filter(_.exists).
          map(findScripts).
          getOrElse(Nil)
      } else {
        // Concated and minified by UglifyJS
        "concat.min.js" :: Nil
      }
    }

    Ok(views.html.index(javascripts))
  }


  def socket = WebSocket.acceptWithActor[String, String] { 
    request => out =>
      AnalysisActor.props(out)
    }

}

Upvotes: 1

Related Questions