spring引导应用程序在连接docker上运行的mongodb时抛出MongoSocketOpenException

spring引导应用程序在连接docker上运行的mongodb时抛出MongoSocketOpenException,mongodb,spring-boot,docker,Mongodb,Spring Boot,Docker,您好,我在docker上运行mongodb映像,安装在windows上的virtual box和spring boot应用程序上,当我运行应用程序时,它显示“异常打开套接字”。我的mongodb在docker上运行良好,我的application.yaml配置可能有问题。我正在将主机定义为本地主机,在这种情况下,localhost将是我的tomcat服务器,它嵌入了spring boot,但在这里,我必须将docker分配给这个主机,但我不知道如何完成。帮助 应用程序.yaml DemoMong

您好,我在docker上运行mongodb映像,安装在windows上的virtual box和spring boot应用程序上,当我运行应用程序时,它显示“异常打开套接字”。我的mongodb在docker上运行良好,我的application.yaml配置可能有问题。我正在将主机定义为本地主机,在这种情况下,localhost将是我的tomcat服务器,它嵌入了spring boot,但在这里,我必须将docker分配给这个主机,但我不知道如何完成。帮助

应用程序.yaml DemoMongoDbApplication.java 堆栈跟踪
演示如何启动mongo容器。您正在发布端口吗?我正在通过docker命令docker run-d--name mongodb--net cms application-p 27017:27017 mongo:3.4.10启动容器演示如何启动mongo容器。你们在发布端口吗?我正在通过docker命令docker run-d——name mongodb——net cms应用程序——p 27017:27017 mongo:3.4.10启动容器
spring:
  data:
    mongodb:
      database: cms
      host: localhost
      port: 27017
package com.example.demomongoDB;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;

@SpringBootApplication
@EnableAutoConfiguration(exclude={MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
public class DemoMongoDbApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoMongoDbApplication.class, args);
    }

}
2019-10-24 17:30:14.370 DEBUG 12024 --- [kground-preinit] .h.v.m.ResourceBundleMessageInterpolator : Loaded expression factory via original TCCL

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.0.RELEASE)

2019-10-24 17:30:14.573  INFO 12024 --- [           main] c.e.demomongoDB.DemoMongoDbApplication   : Starting DemoMongoDbApplication on LAPTOP-QKODI51C with PID 12024 (started by HEMRAJ in D:\D\java projects eclipse\spring boot projects\spring boot CMS\demo-mongoDB)
2019-10-24 17:30:14.575  INFO 12024 --- [           main] c.e.demomongoDB.DemoMongoDbApplication   : No active profile set, falling back to default profiles: default
2019-10-24 17:30:15.611  INFO 12024 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-10-24 17:30:15.636  INFO 12024 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 17ms. Found 0 repository interfaces.
2019-10-24 17:30:15.645  INFO 12024 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-10-24 17:30:15.648  INFO 12024 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1ms. Found 0 repository interfaces.
2019-10-24 17:30:17.211  INFO 12024 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-10-24 17:30:17.226  INFO 12024 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-10-24 17:30:17.227  INFO 12024 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-10-24 17:30:17.377  INFO 12024 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-10-24 17:30:17.377  INFO 12024 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2689 ms
2019-10-24 17:30:17.866  INFO 12024 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-10-24 17:30:18.124  INFO 12024 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2019-10-24 17:30:18.397  WARN 12024 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from class java.time.LocalDateTime to class java.time.Instant as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2019-10-24 17:30:18.398  WARN 12024 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from class java.time.Instant to class java.time.LocalDateTime as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2019-10-24 17:30:18.432  WARN 12024 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from class java.time.LocalDateTime to class java.time.Instant as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2019-10-24 17:30:18.432  WARN 12024 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from class java.time.Instant to class java.time.LocalDateTime as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2019-10-24 17:30:18.653  INFO 12024 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-10-24 17:30:18.658  INFO 12024 --- [           main] c.e.demomongoDB.DemoMongoDbApplication   : Started DemoMongoDbApplication in 4.974 seconds (JVM running for 5.844)
2019-10-24 17:30:22.338  INFO 12024 --- [localhost:27017] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server localhost:27017

com.mongodb.MongoSocketOpenException: Exception opening socket
    at com.mongodb.internal.connection.AsynchronousSocketChannelStream$OpenCompletionHandler.failed(AsynchronousSocketChannelStream.java:117) ~[mongodb-driver-core-3.11.1.jar:na]
    at sun.nio.ch.Invoker.invokeUnchecked(Unknown Source) ~[na:1.8.0_211]
    at sun.nio.ch.Invoker.invokeDirect(Unknown Source) ~[na:1.8.0_211]
    at sun.nio.ch.Invoker.invoke(Unknown Source) ~[na:1.8.0_211]
    at sun.nio.ch.Invoker.invoke(Unknown Source) ~[na:1.8.0_211]
    at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ConnectTask.failed(Unknown Source) ~[na:1.8.0_211]
    at sun.nio.ch.Iocp$EventHandlerTask.run(Unknown Source) ~[na:1.8.0_211]
    at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(Unknown Source) ~[na:1.8.0_211]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[na:1.8.0_211]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[na:1.8.0_211]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_211]
Caused by: java.io.IOException: The remote computer refused the network connection.

    at sun.nio.ch.Iocp.translateErrorToIOException(Unknown Source) ~[na:1.8.0_211]
    at sun.nio.ch.Iocp.access$700(Unknown Source) ~[na:1.8.0_211]
    ... 5 common frames omitted