java.lang.nosuchfieldexception:使用play框架处理嵌入式mongodb

gz5pxeao  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(267)

我试图在测试中启用内存mongodb,我使用simplyscala来完成这项工作。

class controllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting with BeforeAndAfterAll with MongoEmbedDatabase{

  //declares a variable which will hold the reference to running mongoDB Instance
  var mongoInstance: MongodProps = null
  // Start In-memory Mongo instance in before statement
  override def beforeAll(): Unit =
    try{
      val rnd = new scala.util.Random
      val range = 12000 to 36000
      val portNum = range(rnd.nextInt(range length))
      mongoInstance = mongoStart(portNum) } //Try starting mongo on random port number
    catch { case ex:Exception => } // Handle exception In case local mongo is running//code to run before all tests starts
  override def afterAll(): Unit = mongoStop(mongoInstance)

但是我有个错误:

[info] controllerSpec:
java.lang.NoSuchFieldException: handle
        at java.base/java.lang.Class.getDeclaredField(Class.java:2411)
        at de.flapdoodle.embed.process.runtime.Processes.windowsProcessId(Processes.java:109)
        at de.flapdoodle.embed.process.runtime.Processes.access$200(Processes.java:51)
        at de.flapdoodle.embed.process.runtime.Processes$PidHelper$2.getPid(Processes.java:209)
  | => rat de.flapdoodle.embed.process.runtime.Processes.processId(Processes.java:72)
        at de.flapdoodle.embed.process.runtime.ProcessControl.<init>(ProcessControl.java:64)
        at de.flapdoodle.embed.process.runtime.ProcessControl.start(ProcessControl.java:205)
        at de.flapdoodle.embed.process.runtime.AbstractProcess.<init>(AbstractProcess.java:98)
        at de.flapdoodle.embed.mongo.AbstractMongoProcess.<init>(AbstractMongoProcess.java:53)
        at de.flapdoodle.embed.mongo.MongodProcess.<init>(MongodProcess.java:50)
        at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:44)
        at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:34)
        at de.flapdoodle.embed.process.runtime.Executable.start(Executable.java:101)
        at com.github.simplyscala.MongoEmbedDatabase.mongoStart(MongoEmbedDatabase.scala:26)
        at com.github.simplyscala.MongoEmbedDatabase.mongoStart$(MongoEmbedDatabase.scala:22)
        at controllersSpec.ssmServiceSpec.ssmControllerSpec.mongoStart(ssmControllerSpec.scala:22)
        at controllersSpec.ssmServiceSpec.ssmControllerSpec.beforeAll(ssmControllerSpec.scala:32)
        at org.scalatest.BeforeAndAfterAll.liftedTree1$1(BeforeAndAfterAll.scala:212)
        at org.scalatest.BeforeAndAfterAll.run(BeforeAndAfterAll.scala:210)
        at org.scalatest.BeforeAndAfterAll.run$(BeforeAndAfterAll.scala:208)
        at controllersSpec.ssmServiceSpec.ssmControllerSpec.run(ssmControllerSpec.scala:22)
        at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:317)
        at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:510)
        at sbt.ForkMain$Run.lambda$runTest$1(ForkMain.java:304)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)

这跟之前和之后有什么关系吗?如果我做错了什么,请告诉我谢谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题