Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Mongo客户端正在尝试关闭未关闭的连接';t exist/create失败,出现MongoSocketReadException:过早到达流末尾_Java_Spring_Mongodb_Driver - Fatal编程技术网

Java Mongo客户端正在尝试关闭未关闭的连接';t exist/create失败,出现MongoSocketReadException:过早到达流末尾

Java Mongo客户端正在尝试关闭未关闭的连接';t exist/create失败,出现MongoSocketReadException:过早到达流末尾,java,spring,mongodb,driver,Java,Spring,Mongodb,Driver,在调试模式下,我看到我的应用程序日志中有很多“com.mongodb.mongoscocketreadeexception:过早到达流的末尾”的内容,当它试图关闭mongo连接时。到目前为止,我的分析是,我在日志中没有看到按照connectionId{localValue:8}格式的连接id创建的连接 注意:相同的代码适用于org.mongodb:mongodb驱动程序:3.4.2,但我们在3.6.3中看到警告 Mongo客户端版本#3.6.3 Mongo服务器版本#3.2.6(3节点副本集)

在调试模式下,我看到我的应用程序日志中有很多“com.mongodb.mongoscocketreadeexception:过早到达流的末尾”的内容,当它试图关闭mongo连接时。到目前为止,我的分析是,我在日志中没有看到按照connectionId{localValue:8}格式的连接id创建的连接

注意:相同的代码适用于org.mongodb:mongodb驱动程序:3.4.2,但我们在3.6.3中看到警告

Mongo客户端版本#3.6.3 Mongo服务器版本#3.2.6(3节点副本集) Mongo dependencies#org.springframework.data:spring数据mongodb:1.8.2.RELEASE,org.mongodb:mongodb驱动程序:3.6.3

我确实参考并尝试了以下设置,但没有帮助

Mongo客户端配置

<mongo:mongo-client id="sslmongosfp" replica-set="${mongodb.replication.set}" credentials="${MONGO_USER}@${mongodb.dbname}">
    <mongo:client-options ssl="true"
      socket-keep-alive="${mongo.socketKeepAlive:true}"
      socket-timeout="${mongo.socketTimeout:180000}"
      heartbeat-connect-timeout="${mongo.heartbeat.connectTimeout:60000}"
      heartbeat-socket-timeout="${mongo.socketTimeout:180000}"
      max-connection-idle-time="${mongo.max.connection.idle:300000}" />
</mongo:mongo-client>
有用信息

[localhost-startStop-1] 2018-08-07 12:39:57,546  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:39:57,552  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-1-thread-1] 2018-08-07 12:39:57,585  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:39:57,609  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-2-thread-1] 2018-08-07 12:39:57,610  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:39:57,611  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-3-thread-1] 2018-08-07 12:39:57,612  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:39:57,616  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[localhost-startStop-1] 2018-08-07 12:39:57,879  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:39:57,879  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-5-thread-1] 2018-08-07 12:39:57,880  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:39:57,881  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-6-thread-1] 2018-08-07 12:39:57,882  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:39:57,882  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-7-thread-1] 2018-08-07 12:39:57,885  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:39:57,886  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,168  org.mongodb.driver.connection - Opened connection [connectionId{localValue:2, serverValue:41448917}] to MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,168  org.mongodb.driver.cluster - Checking status of MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,173  org.mongodb.driver.connection - Opened connection [connectionId{localValue:3, serverValue:41047679}] to MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,173  org.mongodb.driver.cluster - Checking status of MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,215  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer2:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=40007177, setName='rs0', canonicalAddress=MyServer2:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=null, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155407285407}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,215  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=42769620, setName='rs0', canonicalAddress=MyServer1:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=7fffffff000000000000002d, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155408436207}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,218  org.mongodb.driver.cluster - Discovered cluster type of REPLICA_SET
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,219  org.mongodb.driver.cluster - Setting max election id to 7fffffff000000000000002d from replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,220  org.mongodb.driver.cluster - Setting max set version to 11 from replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,220  org.mongodb.driver.cluster - Discovered replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,220  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=42.8 ms, state=CONNECTED}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,221  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=42.8 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=40.0 ms, state=CONNECTED}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,296  org.mongodb.driver.connection - Opened connection [connectionId{localValue:4, serverValue:41448920}] to MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,296  org.mongodb.driver.cluster - Checking status of MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,296  org.mongodb.driver.connection - Opened connection [connectionId{localValue:6, serverValue:41047689}] to MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,296  org.mongodb.driver.cluster - Checking status of MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,310  org.mongodb.driver.connection - Opened connection [connectionId{localValue:1, serverValue:15360985}] to MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,311  org.mongodb.driver.cluster - Checking status of MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,335  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=38447323, setName='rs0', canonicalAddress=MyServer1:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=7fffffff000000000000002d, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155527879863}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,335  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer2:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=38707927, setName='rs0', canonicalAddress=MyServer2:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=null, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155528294115}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Discovered cluster type of REPLICA_SET
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Setting max election id to 7fffffff000000000000002d from replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Setting max set version to 11 from replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Discovered replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=38.4 ms, state=CONNECTED}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=38.4 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=38.7 ms, state=CONNECTED}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,577  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer3:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=266413679, setName='rs0', canonicalAddress=MyServer3:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=null, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155770298051}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,578  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=42.8 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=40.0 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=266.4 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,626  org.mongodb.driver.connection - Opened connection [connectionId{localValue:5, serverValue:15360986}] to MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,626  org.mongodb.driver.cluster - Checking status of MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,677  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer3:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=50611106, setName='rs0', canonicalAddress=MyServer3:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=null, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155870321060}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,678  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=38.4 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=38.7 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.6 ms, state=CONNECTED}]
[localhost-startStop-1] 2018-08-07 12:40:00,930  org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:41448934}] to MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:40:08,223  org.mongodb.driver.cluster - Checking status of MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:40:08,223  org.mongodb.driver.cluster - Checking status of MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:40:08,256  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=40.7 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=40.0 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=266.4 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:40:08,262  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=40.7 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=39.5 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=266.4 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:40:08,339  org.mongodb.driver.cluster - Checking status of MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:40:08,339  org.mongodb.driver.cluster - Checking status of MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:40:08,436  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=38.4 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.2 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.6 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:40:08,441  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=51.0 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.2 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.6 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:40:08,581  org.mongodb.driver.cluster - Checking status of MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:40:08,631  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=40.7 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=39.5 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=222.9 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:40:08,681  org.mongodb.driver.cluster - Checking status of MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:40:08,735  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=51.0 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.2 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.2 ms, state=CONNECTED}]
[localhost-startStop-1] 2018-08-07 12:40:11,749  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:40:11,749  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-9-thread-1] 2018-08-07 12:40:11,750  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:40:11,751  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-10-thread-1] 2018-08-07 12:40:11,753  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:40:11,755  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-11-thread-1] 2018-08-07 12:40:11,757  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:40:11,759  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[localhost-startStop-1] 2018-08-07 12:40:11,765  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:40:11,765  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-13-thread-1] 2018-08-07 12:40:11,767  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:40:11,767  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-14-thread-1] 2018-08-07 12:40:11,769  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:40:11,770  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-15-thread-1] 2018-08-07 12:40:11,772  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:40:11,774  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[localhost-startStop-1] 2018-08-07 12:40:11,787  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:40:11,787  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-17-thread-1] 2018-08-07 12:40:11,788  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:40:11,788  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-18-thread-1] 2018-08-07 12:40:11,789  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:40:11,790  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-19-thread-1] 2018-08-07 12:40:11,791  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:40:11,792  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[localhost-startStop-1] 2018-08-07 12:40:11,795  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:40:11,795  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-21-thread-1] 2018-08-07 12:40:11,796  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:40:11,797  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-22-thread-1] 2018-08-07 12:40:11,798  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:40:11,799  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-23-thread-1] 2018-08-07 12:40:11,801  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:40:11,802  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb6bd33cf25160031d6c', description='null'}-MyServer1:27017] 2018-08-07 12:40:11,865  org.mongodb.driver.connection - Closing connection connectionId{localValue:8}
[cluster-ClusterId{value='5b69cb6bd33cf25160031d6c', description='null'}-MyServer1:27017] 2018-08-07 12:40:11,865  org.mongodb.driver.cluster - Exception in monitor thread while connecting to server MyServer1:27017
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
    at com.mongodb.connection.SocketStream.read(SocketStream.java:87)
我的申请日志第一条声明开始于2018-08-07 12:39:47040

2018-08-07 12:40:11865开始提前到达终点 这个错误永远重复


从下面的日志中,我发现mongo客户端选项设置不正确 使用以下设置创建的群集{hosts=[MyServer1:27017,MyServer3:27017,MyServer2:27017],mode=MULTIPLE,requiredClusterType=UNKNOWN,serverSelectionTimeout='30000ms',maxWaitQueueSize=500}

更新我的mongo配置以使用下面的方法成功了

<bean id="mongosfpUri" class="com.mongodb.MongoClientURI">
    <!-- refer https://docs.mongodb.com/manual/reference/connection-string/ -->
    <constructor-arg value="${mongodb.uri}"/>
</bean>

<bean id="mongosfp" class="com.mongodb.MongoClient">
    <constructor-arg ref="mongosfpUri"/>
</bean>

<mongo:db-factory id="mongoDbFactory" dbname="${mongodb.dbname}" mongo-ref="mongosfp" />

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg ref="mongoDbFactory" />
    <constructor-arg ref="mongoConverter" />
</bean>

<bean id="mongoConverter" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter">
    <constructor-arg ref="mongoDbFactory" />
    <constructor-arg>
        <bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" />
    </constructor-arg>
    <property name="mapKeyDotReplacement" value="%2E" />
</bean>
mongodb.uri=mongodb://user:password@MyServer1:27017,MyServer2:27017,MyServer3:27017/mydb?replicaSet=rs0&ssl=true&sslInvalidHostNameAllowed=true&heartbeatFrequencyMS=10000