如果我直接从Scalatra文档页面上的示例中获取了一个servlet:
package me.myself.andi
import _root_.akka.dispatch._
import org.scalatra.akka.AkkaSupport
import org.scalatra.ScalatraServlet
class MyAppServlet extends ScalatraServlet with AkkaSupport {
get("/"){
Future {
// Add other logic here
<html><body>Hello Akka</body></html>
}
}
}
我收到错误class MyAppServlet needs to be abstract, since method system in trait AkkaSupport of type => akka.actor.ActorSystem is not
defined
。
然后,我试过了:
package me.myself.andi
import _root_.akka.dispatch._
import org.scalatra.akka.AkkaSupport
import org.scalatra.ScalatraServlet
class MyAppServlet extends ScalatraServlet with AkkaSupport {
val system = ActorSystem("MySystem")
get("/"){
Future(system) { // and also Future {
// Add other logic here
<html><body>Hello Akka</body></html>
}
}
}
但收到另一个错误type mismatch; found : org.scalatra.ActionResult required:
akka.dispatch.ExecutionContext
。对阿卡不熟悉,这里发生了什么?
libraryDependencies ++= Seq(
"org.scalatra" % "scalatra" % "2.2.0-SNAPSHOT",
"org.scalatra" % "scalatra-scalate" % "2.2.0-SNAPSHOT",
"org.scalatra" % "scalatra-specs2" % "2.2.0-SNAPSHOT" % "test",
"org.scalatra" % "scalatra-akka" % "2.2.0-SNAPSHOT",
"com.typesafe.akka" % "akka" % "2.0.4",
"ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",
"eu.infomas" % "annotation-detector" % "3.0.0",
"org.atmosphere" % "atmosphere-runtime" % "1.1.0-SNAPSHOT",
"org.eclipse.jetty" % "jetty-websocket" % "8.1.4.v20120524",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" % "container",
"org.eclipse.jetty" % "test-jetty-servlet" % "8.1.5.v20120716" % "test",
"org.eclipse.jetty" % "jetty-websocket" % "8.1.7.v20120910" % "container",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar"))
)
答案 0 :(得分:3)
编译错误非常清楚。导入akka.actor.ActorSystem
并将val system = ActorSystem("MySystem")
添加到课程中,它应该有效。
编辑:
system
应该是隐式值,因此它必须是implicit val system = ActorSystem("MySystem")
,然后不要手动传入系统。所以总的来说就是
class MyAppServlet extends ScalatraServlet with AkkaSupport {
implicit val system = ActorSystem("MySystem")
get("/"){
Future { // and also Future {
// Add other logic here
<html><body>Hello Akka</body></html>
}
}
}