1

我刚刚使用具有mongoDB-reactive依赖关系的 Spring Tool Suite 创建了一个非常基本的 Spring Boot 项目并运行该应用程序,但是,我不断收到以下异常

2019-11-27 00:31:19.699 INFO 11988 --- [localhost:27017] org.mongodb.driver.cluster:连接到服务器 localhost:27017 时监控线程出现异常

com.mongodb.MongoSocketOpenException:在 com.mongodb.connection.netty.NettyStream$OpenChannelFutureListener.operationComplete(NettyStream.java:410) ~[mongodb-driver-core-3.11.2.jar:na] 处打开套接字的异常

我正在使用 Spring Boot (2.2.1.RELEASE)

在里面applications.properties我添加了以下行

spring.data.mongodb.uri=mongodb://localhost:27017/testdb

我错过了什么?

4

4 回答 4

0

I just noticed that the dependency I added is test scoped. Things have worked after removing it.

    <dependency>
        <groupId>de.flapdoodle.embed</groupId>
        <artifactId>de.flapdoodle.embed.mongo</artifactId>
        <version>2.2.0</version>
    </dependency>
于 2019-12-01T16:28:27.817 回答
0

在我的情况下,我试图从其他 sprint 启动应用程序连接到 k8s 中存在的 mongo 服务,我知道 SpringBoot 具有一些自动配置功能,它在应用程序启动期间默认尝试连接到 localhost:27017,跳过它我必须在应用程序 yaml 中排除它:spring.autoconfigure.exclude:org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration

于 2020-10-22T12:09:22.370 回答
0

MongoSocketOpenException当 spring boot 应用程序无法使用给定的连接详细信息(或默认 localhost 和 27017 端口)连接到 mongo db 时发生

检查 MongoDB 实例是否正在使用 mongo shell 运行,如果失败检查 mongo db server config 的监听接口 ip(启用监听所有接口 - 使用 net config as

net: bindIp: 127.0.0.1 port: 27017

于 2019-11-27T08:41:01.920 回答
0

如果要嵌入 mongo,请添加依赖项 https://mvnrepository.com/artifact/de.flapdoodle.embed/de.flapdoodle.embed.mongo

或者,您可以轻松地在本地安装 mongo 实例。

于 2019-11-27T09:22:31.910 回答