gpt4 book ai didi

mongodb - java.lang.NoSuchFieldException : handle Embedded MongoDB with play framework 异常

转载 作者:行者123 更新时间:2023-12-05 06:01:13 25 4
gpt4 key购买 nike

我正在尝试在测试中启用内存中的 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)

和BeforeAndAfterAll有关系吗?如果我做错了什么请告诉我谢谢。

最佳答案

升级Embedded MongoDB依赖测试驱动版本到3.4.3

Gradle :

testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo:3.4.3'

pom.xml

<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>3.4.3</version> <!-- make this version a property instead-->
<scope>test</scope>
</dependency>

关于mongodb - java.lang.NoSuchFieldException : handle Embedded MongoDB with play framework 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67280800/

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