范围内的 Play 框架隐式应用程序

Play framework implicit application in scope

我刚开始使用 sbt-multi 项目。但是我 运行 遇到以下问题:

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

此行包含:if (Play.isDev) { 并且可以在此处看到:https://github.com/dataplayground/twitterPipeline/blob/master/modules/frontend/app/controllers/Application.scala

问题是:即使我导入了它,仍然有一个新错误告诉我找不到 Play

上下文: 我想使用 angular.

设置一个简单的网络套接字

编辑:

您好,非常感谢。这部分似乎有效。但是我在其他方法中也确实需要这个变量。如果我将它添加到 class 的整个范围内,我会收到以下错误

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. 

如果我尝试手动将其添加到第二种方法,例如

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

我收到上面的错误。

您需要 Application 在隐式范围内。以下将起作用。

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

}