Spring Data MongoDB - java.net.SocketException:连接重置

时间:2013-08-23 08:42:23

标签: java mongodb spring-data spring-data-mongodb nosql

当我尝试使用 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

1 个答案:

答案 0 :(得分:-1)

是dbserver你真正的主机名吗?

防火墙会阻止它吗?

你可以从命令行到达mongodb吗?来自GUI客户端?

请参阅:What's causing my java.net.SocketException: Connection reset?