【问题标题】:Docker, Mongodb,Spring Boot on Windows getting Connection refused errorDocker,Mongodb,Windows 上的 Spring Boot 出现连接被拒绝错误
【发布时间】:2019-07-27 13:52:18
【问题描述】:

我正在使用 MongoDB 的默认 docker 映像,并尝试在 windows 框中使用简单的 spring Boot 应用程序进行连接。

mongoDB 图像被正确盯着

mongoDB 映像中的 IP

我的课程路径中有spring-boot-starter-data-mongodb。我正在使用所有 Spring Boot 默认值,并且仅在 application.properties 中使用以下属性。

spring.data.mongodb.host=192.168.99.100

在应用程序启动时得到Connection denied: connect错误

日志

019-03-06 06:15:06.096  INFO 4664 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[192.168.99.100:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2019-03-06 06:15:06.096  INFO 4664 --- [           main] org.mongodb.driver.cluster               : Adding discovered server 192.168.99.100:27017 to client view of cluster
2019-03-06 06:15:06.356  WARN 4664 --- [           main] o.s.d.m.c.m.BasicMongoPersistentProperty : Customizing field name for id property not allowed! Custom name will not be considered!
2019-03-06 06:15:06.928  INFO 4664 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-03-06 06:15:07.164  INFO 4664 --- [68.99.100:27017] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server 192.168.99.100:27017

我在这里缺少什么?

【问题讨论】:

  • 您可以使用命令行或指南针进行连接吗?
  • 感谢您的检查,我是 Mongo 和 docker 的新手。我该如何检查?
  • 是的,我可以使用命令行连接
  • 也许在 mongod.conf 中你需要更改 bind_ip = 0.0.0.0。默认是本地主机

标签: spring mongodb spring-boot docker


【解决方案1】:

不是 MongoDB 专家,而是一个温和的 Docker 用户发言:您似乎没有发布 MongoDB 默认运行的端口:27017。这就是为什么您的 spring 应用程序无法获得连接并抛出此异常的原因:

Exception in monitor thread while connecting to server 192.168.99.100:27017

所以你可以尝试在启动 mongo 容器时使用-p 27017:27017发布端口。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-19
    • 2019-06-06
    • 1970-01-01
    • 2018-08-29
    • 2021-09-20
    • 2020-10-11
    • 2021-05-23
    相关资源
    最近更新 更多