java—从maven exec连接到mongodb失败,但不是从jar

ycggw6v2  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(248)

下面的命令解析执行我的程序所需的所有依赖项: mvn exec:java -Dexec.mainClass='com.cnrg.cdproc.App' 但我无法用它连接到mongodb,因为可以使用以下命令从jar执行相同的代码: java -jar target/cdproc-1.0.0-SNAPSHOT-shaded.jar .
以下是我通过maven启动应用程序时遇到的错误:

[Thread-1] INFO org.mongodb.driver.cluster - Cluster created with settings {hosts=[localhost:9032], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
[cluster-ClusterId{value='5fc969c67d495439ce9a3796', description='null'}-localhost:9032] INFO org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:9032
com.mongodb.MongoInterruptedException: Interrupted acquiring a permit to retrieve an item from the pool 
    at com.mongodb.internal.connection.ConcurrentPool.acquirePermit(ConcurrentPool.java:203)
    at com.mongodb.internal.connection.ConcurrentPool.get(ConcurrentPool.java:140)
    at com.mongodb.internal.connection.ConcurrentPool.get(ConcurrentPool.java:123)
    at com.mongodb.internal.connection.PowerOfTwoBufferPool.getByteBuffer(PowerOfTwoBufferPool.java:82)
    at com.mongodb.internal.connection.PowerOfTwoBufferPool.getBuffer(PowerOfTwoBufferPool.java:77)
    at com.mongodb.internal.connection.SocketStream.getBuffer(SocketStream.java:93)
    at com.mongodb.internal.connection.InternalStreamConnection.getBuffer(InternalStreamConnection.java:684)
    at com.mongodb.internal.connection.ByteBufferBsonOutput.getByteBufferAtIndex(ByteBufferBsonOutput.java:93)
    at com.mongodb.internal.connection.ByteBufferBsonOutput.getCurrentByteBuffer(ByteBufferBsonOutput.java:82)
    at com.mongodb.internal.connection.ByteBufferBsonOutput.writeByte(ByteBufferBsonOutput.java:77)
    at org.bson.io.OutputBuffer.write(OutputBuffer.java:150)
    at org.bson.io.OutputBuffer.writeInt32(OutputBuffer.java:56)
    at com.mongodb.internal.connection.RequestMessage.writeMessagePrologue(RequestMessage.java:158)
    at com.mongodb.internal.connection.RequestMessage.encode(RequestMessage.java:137)
    at com.mongodb.internal.connection.CommandMessage.encode(CommandMessage.java:59)
    at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:269)
    at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83)
    at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33)
    at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:107)
    at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:62)
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:144)
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:188)
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.InterruptedException
    at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1343)
    at java.base/java.util.concurrent.Semaphore.acquire(Semaphore.java:318)
    at com.mongodb.internal.connection.ConcurrentPool.acquirePermit(ConcurrentPool.java:199)
    ... 23 more

通过jar启动程序和通过maven启动程序有什么区别?如果可能的话,如何解决这个问题并从maven启动程序?

暂无答案!

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

相关问题