当我尝试使用Spring Data MongoDB在 MongoDB 上持久化数据时出现标题中的错误。
这是我的配置:
<!-- Mongo Configuration -->
<mongo:repositories base-package="com.tk.detective" />
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory" />
</bean>
<!-- local config -->
<mongo:db-factory id="mongoDbFactory" dbname="detective" host="dbserver" port="27017" mongo-ref="mongoRef"/>
<mongo:mongo id="mongoRef" host="dbserver" port="27017">
<mongo:options connections-per-host="100" threads-allowed-to-block-for-connection-multiplier="50" connect-timeout="1000" max-wait-time="2500"
auto-connect-retry="true" socket-keep-alive="true" socket-timeout="15000" slave-ok="true" />
</mongo:mongo>
当我尝试保存任何对象时出现错误:
mongoTemplate.save(object);
完整的错误堆栈跟踪:
Caused by: com.mongodb.MongoException$Network: Write operation to server dbserver/xxx.xx.xx.xx:27017 failed on database detective
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:153) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:115) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:248) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.DBCollection.insert(DBCollection.java:148) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.DBCollection.insert(DBCollection.java:91) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.DBCollection.save(DBCollection.java:810) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.DBCollection.save(DBCollection.java:786) ~[mongo-java-driver-2.11.2.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate$10.doInCollection(MongoTemplate.java:884) ~[spring-data-mongodb-1.2.3.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:388) ~[spring-data-mongodb-1.2.3.RELEASE.jar:na]
... 53 common frames omitted
Caused by: java.net.SocketException: Connection reset
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113) ~[na:1.7.0_07]
at java.net.SocketOutputStream.write(SocketOutputStream.java:153) ~[na:1.7.0_07]
at org.bson.io.PoolOutputBuffer.pipe(PoolOutputBuffer.java:129) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.OutMessage.pipe(OutMessage.java:236) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.DBPort.go(DBPort.java:133) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.DBPort.go(DBPort.java:102) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.DBPort.say(DBPort.java:97) ~[mongo-java-driver-2.11.2.jar:na]
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:140) ~[mongo-java-driver-2.11.2.jar:na]
... 62 common frames omitted