Closed connection [connectionId{XXXX}] to 172.16.11.47:27017

  • 2019 年 11 月 3 日
  • 筆記

Closed connection [connectionId{XXXX}] to 172.16.11.47:27017 because the pool has been closed

启动直接报错,

环境为 springboot mongo

  .   ____          _            __ _ _   /\ / ___'_ __ _ _(_)_ __  __ _      ( ( )___ | '_ | '_| | '_ / _` |       \/  ___)| |_)| | | | | || (_| |  ) ) ) )    '  |____| .__|_| |_|_| |___, | / / / /   =========|_|==============|___/=/_/_/_/   :: Spring Boot ::        (v2.0.3.RELEASE)    2019-10-29 20:25:15.078  INFO 26552 --- [           main] c.c.f.f.i.p.DefaultApplicationProvider   : App ID is set to app-linglong-submit by app.id property from /META-INF/app.properties  2019-10-29 20:25:15.085  INFO 26552 --- [           main] c.c.f.f.i.p.DefaultServerProvider        : Loading C:optsettingsserver.properties  2019-10-29 20:25:15.085  INFO 26552 --- [           main] c.c.f.f.i.p.DefaultServerProvider        : Environment is set to [DEV] by property 'env' in server.properties.  2019-10-29 20:25:16.800  INFO 26552 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!  2019-10-29 20:25:16.844  INFO 26552 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!  2019-10-29 20:25:17.843  INFO 26552 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]  2019-10-29 20:25:17.844  INFO 26552 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31  2019-10-29 20:25:17.849  INFO 26552 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:softJavajdk1.8.0_131bin;C:WindowsSunJavabin;C:Windowssystem32;C:Windows;C:ProgramDataOracleJavajavapath;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsiCLS;C:Program FilesIntelIntel(R) Management Engine ComponentsiCLS;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;C:Program FilesIntelIntel(R) Management Engine ComponentsIPT;C:Program FilesGitcmd;D:softapache-maven-3.6.0bin;D:softmysql-5.7.25-winx64bin;D:softJavajdk1.8.0_131bin;C:Program Filesnodejs;C:Program Files (x86)Rationalcommon;C:Program FilesMozilla Firefox;D:softxamppphp;C:Program Fileserl10.4bin;D:softadb;D:softPythonPython37Scripts;D:softPythonPython37;C:UsersqubianzhongAppDataLocalMicrosoftWindowsApps;C:UsersqubianzhongAppDataRoamingnpm;D:softMicrosoft VS Codebin;C:UsersqubianzhongAppDataLocalBypassRuntm;C:Program FilesJetBrainsWebStorm 2019.1.3bin;;.]  2019-10-29 20:25:17.993  INFO 26552 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext  2019-10-29 20:25:18.259  INFO 26552 --- [           main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource  2019-10-29 20:25:18.405  INFO 26552 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited  2019-10-29 20:25:19.927  INFO 26552 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[172.16.11.47:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}  2019-10-29 20:25:20.011  INFO 26552 --- [.16.11.47:27017] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:1, serverValue:709}] to 172.16.11.47:27017  2019-10-29 20:25:20.020  INFO 26552 --- [.16.11.47:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=172.16.11.47:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 19]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=8155700}  2019-10-29 20:25:20.322  INFO 26552 --- [           main] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:2, serverValue:710}] to 172.16.11.47:27017  2019-10-29 20:25:20.772  INFO 26552 --- [           main] org.mongodb.driver.connection            : Closed connection [connectionId{localValue:2, serverValue:710}] to 172.16.11.47:27017 because the pool has been closed.  2019-10-29 20:25:20.775  INFO 26552 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closed  2019-10-29 20:25:20.775  INFO 26552 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]  Disconnected from the target VM, address: '127.0.0.1:61892', transport: 'socket'    Process finished with exit code 1

我这个导致的原因是 项目里使用了RestTemplate, 但是在配置的过程中有改动,导致的问题

出现问题的RestTemplate配置代码

package com.xxx.yyy.config;    import org.springframework.context.annotation.Bean;  import org.springframework.context.annotation.Configuration;  import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;  import org.springframework.web.client.RestTemplate;    @Configuration  public class RestTemplateConfig {        @Bean      public RestTemplate restTemplate(OkHttp3ClientHttpRequestFactory factory){          return new RestTemplate(factory);      }        @Bean      public OkHttp3ClientHttpRequestFactory simpleClientHttpRequestFactory(){          OkHttp3ClientHttpRequestFactory factory = new OkHttp3ClientHttpRequestFactory();          factory.setConnectTimeout(60*1000);          factory.setReadTimeout(60*1000);          return factory;      }    }

修改为原来的,再次启动,正常启动

package com.xxx.yyy.config;    import org.springframework.context.annotation.Bean;  import org.springframework.context.annotation.Configuration;  import org.springframework.http.client.ClientHttpRequestFactory;  import org.springframework.http.client.SimpleClientHttpRequestFactory;  import org.springframework.web.client.RestTemplate;    @Configuration  public class RestTemplateConfig {        @Bean      public RestTemplate restTemplate(ClientHttpRequestFactory factory){          return new RestTemplate(factory);      }        @Bean      public ClientHttpRequestFactory simpleClientHttpRequestFactory(){          SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();          factory.setConnectTimeout(60*1000);          factory.setReadTimeout(60*1000);          return factory;      }    }