복붙노트

[SPRING] Mongo가 자동으로 포트 27017 (로컬 호스트)에 연결하려고 시도합니다.

SPRING

Mongo가 자동으로 포트 27017 (로컬 호스트)에 연결하려고 시도합니다.

Maven에서 Spring Rest와 Mongo를 사용하여 서버에 연결하는 웹 서비스를 만들고 있습니다. 문제는 Mongo에 대한 코드를 작성하지 않았으며 localhost에 연결하려고 시도하여 MongoSocketOpenException을 던지고 있다는 것입니다. 필자가 작성한 유일한 코드는 main.This에서 스프링을 시작하는 두 행의 코드입니다. 스택 추적입니다.

2015-12-22 12:46:43.193  INFO 5720 --- [           main] fhirepsos.ws.Server                      : Starting Server on HarisPC with PID 5720 (C:\Users\Haris\workspace\FHIRtoepSOSConversion\target\classes started by Haris in C:\Users\Haris\workspace\FHIRtoepSOSConversion)
2015-12-22 12:46:43.197  INFO 5720 --- [           main] fhirepsos.ws.Server                      : No profiles are active
2015-12-22 12:46:43.260  INFO 5720 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@31f924f5: startup date [Tue Dec 22 12:46:43 EET 2015]; root of context hierarchy
2015-12-22 12:46:44.007  INFO 5720 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'beanNameViewResolver' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2015-12-22 12:46:44.735  INFO 5720 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 9001 (http)
2015-12-22 12:46:44.750  INFO 5720 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2015-12-22 12:46:44.751  INFO 5720 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.28
2015-12-22 12:46:44.865  INFO 5720 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2015-12-22 12:46:44.866  INFO 5720 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1610 ms
2015-12-22 12:46:45.161  INFO 5720 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2015-12-22 12:46:45.166  INFO 5720 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-12-22 12:46:45.166  INFO 5720 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2015-12-22 12:46:45.167  INFO 5720 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2015-12-22 12:46:45.167  INFO 5720 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'requestContextFilter' to: [/*]
2015-12-22 12:46:45.393  INFO 5720 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@31f924f5: startup date [Tue Dec 22 12:46:43 EET 2015]; root of context hierarchy
2015-12-22 12:46:45.467  INFO 5720 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2015-12-22 12:46:45.468  INFO 5720 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2015-12-22 12:46:45.499  INFO 5720 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-12-22 12:46:45.499  INFO 5720 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-12-22 12:46:45.539  INFO 5720 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-12-22 12:46:45.726  INFO 5720 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2015-12-22 12:46:45.796  INFO 5720 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2015-12-22 12:46:45.874  INFO 5720 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9001 (http)
2015-12-22 12:46:45.878  INFO 5720 --- [           main] fhirepsos.ws.Server                      : Started Server in 3.033 seconds (JVM running for 3.383)
2015-12-22 12:46:46.764  INFO 5720 --- [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.connection.SocketStream.open(SocketStream.java:63) ~[mongo-java-driver-3.2.0.jar:na]
    at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114) ~[mongo-java-driver-3.2.0.jar:na]
    at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128) ~[mongo-java-driver-3.2.0.jar:na]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_65]
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_65]
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) ~[na:1.8.0_65]
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:1.8.0_65]
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:1.8.0_65]
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_65]
    at java.net.PlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_65]
    at java.net.SocksSocketImpl.connect(Unknown Source) ~[na:1.8.0_65]
    at java.net.Socket.connect(Unknown Source) ~[na:1.8.0_65]
    at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50) ~[mongo-java-driver-3.2.0.jar:na]
    at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongo-java-driver-3.2.0.jar:na]
    ... 3 common frames omitted  

이것은 내 pom.xml입니다.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>fhirepsos.ws</groupId>
  <artifactId>FHIRtoepSOSConversion</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>FHIR to epSOS Conversion</name>
  <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>1.3.0.RELEASE</version>
  </parent>
  <dependencies>
   <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
   </dependency> 
   <dependency>
       <groupId>org.mongodb</groupId>
       <artifactId>mongo-java-driver</artifactId>
       <version>3.2.0</version>
   </dependency>     
   <dependency>
       <groupId>ca.uhn.hapi.fhir</groupId>
       <artifactId>hapi-fhir-base</artifactId>
       <version>1.3</version>
   </dependency>
   <dependency>
       <groupId>ca.uhn.hapi.fhir</groupId>
       <artifactId>hapi-fhir-structures-dstu2</artifactId>
       <version>1.3</version>
   </dependency>        
  </dependencies>
  <properties>
      <java.version>1.8</java.version>
  </properties>
  <build>
      <plugins>
          <plugin>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
      </plugins>
  </build>
  <repositories>
      <repository>
          <id>spring-releases</id>
          <url>https://repo.spring.io/libs-release</url>
      </repository>
  </repositories>
  <pluginRepositories>
      <pluginRepository>
          <id>spring-releases</id>
          <url>https://repo.spring.io/libs-release</url>
      </pluginRepository>
  </pluginRepositories>  
</project>

마지막으로 예외가 있지만 프로그램이 잘 작동 함을 명시해야합니다.

미리 감사드립니다.

해결법

  1. ==============================

    1.스프링 부트에는 "자동 구성"이라는 기능이 있습니다. 이 경우 classpath에서 Mongo 드라이버가 감지 되 자마자 MongoAutoConfiguration이 localhost : 27017을 가리키는 기본값으로 활성화됩니다. 이 동작을 원하지 않으면 MongoDB의 속성을 구성하거나 (http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-mongodb 유효성을 참조하십시오) 속성 키) 또는 MongoAutoConfiguration을 비활성화합니다.

    스프링 부트에는 "자동 구성"이라는 기능이 있습니다. 이 경우 classpath에서 Mongo 드라이버가 감지 되 자마자 MongoAutoConfiguration이 localhost : 27017을 가리키는 기본값으로 활성화됩니다. 이 동작을 원하지 않으면 MongoDB의 속성을 구성하거나 (http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-mongodb 유효성을 참조하십시오) 속성 키) 또는 MongoAutoConfiguration을 비활성화합니다.

    @SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
    
  2. ==============================

    2.Spring 부트는 Mongo DB가 실행되지 않을 때이 예외를 throw합니다. Mongodb가 실행 중인지 확인하십시오. Mongo DB를 시작한 후 해결되었습니다.

    Spring 부트는 Mongo DB가 실행되지 않을 때이 예외를 throw합니다. Mongodb가 실행 중인지 확인하십시오. Mongo DB를 시작한 후 해결되었습니다.

  3. from https://stackoverflow.com/questions/34414367/mongo-tries-to-connect-automatically-to-port-27017localhost by cc-by-sa and MIT license