Question

If I have a servlet taken directly from the example on the Scalatra docs page:

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

I get an error class MyAppServlet needs to be abstract, since method system in trait AkkaSupport of type => akka.actor.ActorSystem is not defined.

Then, I tried:

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

But receive another error type mismatch; found : org.scalatra.ActionResult required: akka.dispatch.ExecutionContext. Being unfamiliar with Akka, what's going on here?

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"))
)
Was it helpful?

Solution

The compiler error is quite clear. Import akka.actor.ActorSystem and add val system = ActorSystem("MySystem") to the class and it should work.

edit:

The system should be an implicit value, so it has to be implicit val system = ActorSystem("MySystem") and then don't pass in the system manually. So in total it would be

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>
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top