gpt4 book ai didi

scala - 默认 AkkaSupport Servlet 示例不起作用

转载 作者:行者123 更新时间:2023-12-04 05:21:39 28 4
gpt4 key购买 nike

如果我有一个直接取自 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
.不熟悉Akka,这是怎么回事?
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"))
)

最佳答案

编译器错误很明显。进口 akka.actor.ActorSystem并添加 val system = ActorSystem("MySystem")到类(class),它应该工作。

编辑:
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>
}
}
}

关于scala - 默认 AkkaSupport Servlet 示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13633309/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com