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:\opt\settings\server.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:\soft\Java\jdk1.8.0_131\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Git\cmd;D:\soft\apache-maven-3.6.0\bin;D:\soft\mysql-5.7.25-winx64\bin;D:\soft\Java\jdk1.8.0_131\bin;C:\Program Files\nodejs\;C:\Program Files (x86)\Rational\common;C:\Program Files\Mozilla Firefox;D:\soft\xampp\php;C:\Program Files\erl10.4\bin;D:\soft\adb;D:\soft\Python\Python37\Scripts\;D:\soft\Python\Python37\;C:\Users\qubianzhong\AppData\Local\Microsoft\WindowsApps;C:\Users\qubianzhong\AppData\Roaming\npm;D:\soft\Microsoft VS Code\bin;C:\Users\qubianzhong\AppData\Local\BypassRuntm;C:\Program Files\JetBrains\WebStorm 2019.1.3\bin;;.]
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;
    }

}

你可能感兴趣的:(极客公社)