我刚刚开始使用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设置一个简单的Web套接字。
嗨,非常感谢。这部分似乎有效。但是我在其他方法中也需要这个变量。如果我将它添加到类的整个范围内,我会收到以下错误
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)
}
我从上面收到错误。
答案 0 :(得分:1)
隐式范围内需要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)
}
}