【问题标题】:java.lang.NoSuchMethodError with Scala actorsjava.lang.NoSuchMethodError 与 Scala 演员
【发布时间】:2014-06-29 00:22:56
【问题描述】:

我有一个想要测试的简单 Scala 应用程序 (taken from here)。 整个项目使用 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"

【问题讨论】:

    标签: scala sbt akka scalatest testkit


    【解决方案1】:

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

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

    应该是

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

    【讨论】:

      猜你喜欢
      • 2011-01-20
      • 2011-01-30
      • 2010-10-07
      • 2019-04-23
      • 2011-02-20
      • 2023-03-30
      • 2010-10-03
      • 2021-02-09
      • 1970-01-01
      相关资源
      最近更新 更多