Play Specs2测试:ReactiveMongoPlugin错误

时间:2015-06-08 10:33:10

标签: mongodb scala playframework akka specs2

我正在使用Play Framework,Akka Persistent actor和MongoDB。

当我使用FakeApplication运行我的Specs2测试时,抛出了java.lang.ExceptionInInitializerError,原因如下:

Caused by: @6md6ke2n9: ReactiveMongoPlugin Error
    at play.modules.reactivemongo.ReactiveMongoPlugin$.current(ReactiveMongoPlugin.scala:83)
    at play.modules.reactivemongo.ReactiveMongoPlugin$.db(ReactiveMongoPlugin.scala:78)
    at models.daos.TaskDAO$.<init>(TaskDAO.scala:25)
    at models.daos.TaskDAO$.<clinit>(TaskDAO.scala)

调用ReactiveMongoPlugin.db时会发生这种情况。

def db: reactivemongo.api.DB = ReactiveMongoPlugin.db

  val futureCollection: Future[JSONCollection] = {
    val db = ReactiveMongoPlugin.db
    // ...
  }

自从我开始使用PersistentActor以来,就出现了这个问题。我不知道akka-persistence和reactive-mongo依赖项之间是否存在冲突。以下是我的build.sbt:

name := "fmcloud"

version := "0.1"

scalaVersion := "2.11.6"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

resolvers := ("Atlassian Releases" at "https://maven.atlassian.com/public/") +: resolvers.value

resolvers += Resolver.sonatypeRepo("snapshots")
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/releases"

libraryDependencies ++= Seq(
  "javax.inject" % "javax.inject" % "1",
  "org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23",
  "net.codingwell" %% "scala-guice" % "4.0.0-beta5",
  "org.webjars" % "bootstrap" % "3.3.1",
  "org.webjars" % "angularjs" % "1.3.8",
  "org.webjars" % "angular-ui-bootstrap" % "0.12.0",
  "org.mockito" % "mockito-core" % "1.10.17" % "test",
  "com.mohiva" %% "play-silhouette-testkit" % "2.0" % "test",
  "com.mohiva" %% "play-silhouette" % "2.0",
  "org.json" % "json" % "20141113",
  "javax.websocket" % "javax.websocket-client-api" % "1.1",
  "org.glassfish.tyrus" % "tyrus-container-grizzly-client" % "1.4",
  "com.typesafe.akka" % "akka-testkit_2.11" % "2.3.10",
  "com.typesafe.akka" % "akka-persistence-experimental_2.11" % "2.3.10",
  "com.github.ironfish" %% "akka-persistence-mongo-casbah"  % "0.7.5" % "compile"
)
编辑:这可能是IntelliJ IDEA问题。我更新了IntelliJ和Scala插件,现在没有ReactiveMongoPlugin错误。不幸的是,现在所有测试用例都工作,除了一个(涉及PersistentActor)。 它仍然抛出java.lang.ExceptionInInitializerError但原因不同:

Caused by: java.lang.RuntimeException: There is no started application
at scala.sys.package$.error(package.scala:27)
    at play.api.Play$$anonfun$current$1.apply(Play.scala:71)
    at play.api.Play$$anonfun$current$1.apply(Play.scala:71)
    at scala.Option.getOrElse(Option.scala:121)
    at play.api.Play$.current(Play.scala:71)
    at models.daos.TaskDAO$.<init>(TaskDAO.scala:26)
    at models.daos.TaskDAO$.<clinit>(TaskDAO.scala)
    ... 19 more

EDIT2:我注意到只有当我使用持久性actor的TestActorRef时才会出现此错误。

0 个答案:

没有答案