带有MongoDB错误的Vertx-ClassNotFoundException:com.mongodb.connection.StreamFactoryFactory

时间:2018-08-30 12:14:03

标签: java mongodb rest exception vert.x

我正在尝试用Java构建Vert.x REST服务,该服务将数据存储在MongoDB数据库中

我尝试运行此代码-

@Override
public void start(Future<Void> fut) throws Exception {


    router = Router.router(vertx);
    router.route().handler(BodyHandler.create());

    vertx.createHttpServer().requestHandler(router::accept)
            .listen(
                    config().getInteger("http.port", 8080),
                    result -> {
                        if (result.succeeded()) {
                            fut.complete();
                        } else {
                            fut.fail(result.cause());
                        }
                    });
    router.post("/analyze").handler(this::analyze);

//  JsonObject config = new JsonObject()
//  .put("connection_string", "mongodb://localhost:27017")
//  .put("db_name", "words");
    MongoClient client = MongoClient.createShared(vertx, new JsonObject());

并在每次执行中获取此异常-

java.lang.NoClassDefFoundError: com/mongodb/connection/StreamFactoryFactory
    at com.mongodb.async.client.MongoClientSettings.builder(MongoClientSettings.java:69)
    at io.vertx.ext.mongo.impl.config.MongoClientOptionsParser.<init>(MongoClientOptionsParser.java:30)
    at io.vertx.ext.mongo.impl.MongoClientImpl$MongoHolder.mongo(MongoClientImpl.java:928)
    at io.vertx.ext.mongo.impl.MongoClientImpl.<init>(MongoClientImpl.java:113)
    at io.vertx.ext.mongo.MongoClient.createShared(MongoClient.java:68)
    at test.project1.Server.start(Server.java:41)
    at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:483)
    at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:339)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.ClassNotFoundException: com.mongodb.connection.StreamFactoryFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
    ... 14 more
SEVERE: Failed in deploying verticle

网络和文档中提供的所有解决方案均无济于事

0 个答案:

没有答案