异步mongodb客户端vert.x

时间:2016-12-03 21:45:05

标签: java mongodb vert.x

我使用此代码连接到localhost mongodb数据库。 连接后,当我想要检索数据时,我得到了这个例外。

SEVERE: com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback(Lcom/mongodb/async/SingleResultCallback;)Lcom/mongodb/async/SingleResultCallback;
java.lang.NoSuchMethodError: com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback(Lcom/mongodb/async/SingleResultCallback;)Lcom/mongodb/async/SingleResultCallback;
    at com.mongodb.async.client.MongoClientImpl$2.execute(MongoClientImpl.java:100)
    at com.mongodb.async.client.OperationIterable.batchCursor(OperationIterable.java:132)
    at com.mongodb.async.client.OperationIterable.into(OperationIterable.java:64)
    at com.mongodb.async.client.FindIterableImpl.into(FindIterableImpl.java:162)
    at io.vertx.ext.mongo.impl.MongoClientImpl.findWithOptions(MongoClientImpl.java:235)
    at io.vertx.ext.mongo.impl.MongoClientImpl.find(MongoClientImpl.java:217)
    at verticle.ServerVerticle.start(ServerVerticle.java:53)
    at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:434)
    at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:316)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:440)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
    at java.lang.Thread.run(Thread.java:745)

我的代码:

MongoClient mongoClient = MongoClient.createShared(vertx, config().getJsonObject("mongodb"));
        mongoClient.find("user",new JsonObject(),res->{
            if (res.succeeded()){
                List<JsonObject> jsonObjects=res.result();
                String name="ali";
                LOGGER.warn(jsonObjects.toString());
            }
            else{
                String name="name";
            }

        });

下面的Mongodb配置包含db_name,端口,主机和我需要连接到数据库的更多选项。这些选项适用于mongodb同步客户端(我之前使用过)。

"mongodb": {
    "host" : "127.0.0.1",
    "port" : 27017,
    "db_name":"amibackend",
    "maxPoolSize" : 50,
    "minPoolSize" : 25,
    "maxIdleTimeMS" : 300000,
    "maxLifeTimeMS" : 3600000,
    "waitQueueMultiple"  : 10,
    "waitQueueTimeoutMS" : 10000,
    "maintenanceFrequencyMS" : 2000,
    "maintenanceInitialDelayMS" : 500
  }

=============================================== =
该项目的依赖性:(Vert.x)

<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-core</artifactId>
    <version>3.3.3</version>
</dependency>

<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-web</artifactId>
    <version>3.3.3</version>
</dependency>


<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-mongo-client</artifactId>
    <version>3.3.3</version>
</dependency>

1 个答案:

答案 0 :(得分:0)

我认为你的mongodb驱动程序版本有问题。 我建议您升级mongodb驱动程序。

current version of ErrorHandlingResultCallback.java

history version of ErrorHandlingResultCallback.java