java.lang.NoSuchMethodError with Scala actors



我有一个简单的Scala应用程序(取自这里),我想测试一下。整个项目用SBT编译成功但是,当我使用sbt test启动测试时,我得到以下错误消息:

Could not run test ConnectionTest:java.lang.NoSuchMethodError: akka.actor.Props$.apply(Lscala/Function0;)Lakka/actor/Props;

从网上搜索,我得到的印象是,我的一些版本是不兼容的,但这仅仅是一个猜测。可能出了什么问题?

(测试用例)

import akka.actor.{Props, Actor, ActorSystem, ActorRef}
import akka.testkit.{TestKit, TestActorRef, ImplicitSender}
import org.scalatest.{WordSpecLike, BeforeAndAfterAll}
import org.scalatest.matchers.MustMatchers
class ConnectionTest extends TestKit(ActorSystem("ConnectionSpec"))
  with WordSpecLike
  with MustMatchers 
  with BeforeAndAfterAll {
  override def afterAll() { system.shutdown() }
  "Server" must {
    "bind to port " in {
      // create server
      val server  = system.actorOf(Props[Server], name = "server")
      expectMsg("Bound to /127.0.0.1:8888")
    }    
  }
}

[build.sbt]

name := "MyApp"
version := "0.2"
scalaVersion := "2.10.4"
mainClass := Some("akka.Main")
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies +=
"com.typesafe.akka" %% "akka-actor" % "2.3.2"
libraryDependencies += 
"com.typesafe.akka" %% "akka-testkit" % "2.1.4" % "test"
libraryDependencies += 
"org.scalatest" % "scalatest_2.10" % "2.0" % "test"

您需要为testkit使用相同版本的Akka。

libraryDependencies += 
"com.typesafe.akka" %% "akka-testkit" % "2.1.4" % "test"
应该

libraryDependencies += 
"com.typesafe.akka" %% "akka-testkit" % "2.3.2" % "test"

相关内容

  • 没有找到相关文章

最新更新