0

我在同一台机器上运行了 MongoDb 和 Spring MVC 应用程序。出于某种原因,我在尝试通过 Spring MVC 应用程序访问数据时出现读取操作错误。

Caused by: com.mongodb.MongoException$Network: Read operation to server /192.168.1.79:28017 failed on database utilDb
        at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:253)
        at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
        at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288)
        at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273)
        at com.mongodb.DB.getCollectionNames(DB.java:399)
        at com.mongodb.DB.collectionExists(DB.java:441)
        at org.springframework.data.mongodb.core.MongoTemplate$5.doInDB(MongoTemplate.java:438)
        at org.springframework.data.mongodb.core.MongoTemplate$5.doInDB(MongoTemplate.java:436)
        at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:372)
        ... 37 more
Caused by: java.io.EOFException
        at org.bson.io.Bits.readFully(Bits.java:48)
        at org.bson.io.Bits.readFully(Bits.java:33)
        at org.bson.io.Bits.readFully(Bits.java:28)
        at com.mongodb.Response.<init>(Response.java:40)
        at com.mongodb.DBPort.go(DBPort.java:142)
        at com.mongodb.DBPort.call(DBPort.java:92)
        at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:244)
        ... 45 more

这是我在 Spring 中的 app.xml 上的配置:

    <!-- Mongo DB Conf -->
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
    <property name="host" value="192.168.1.79"></property>
    <property name="port" value="28017"></property>
</bean>

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg name="mongo" ref="mongo"></constructor-arg>
    <constructor-arg name="databaseName" value="utilDb"></constructor-arg>
</bean>

提前感谢您的任何意见。

4

2 回答 2

0

Try this.

options.connectionsPerHost = 100;
options.maxWaitTime = 2000;
options.socketKeepAlive = true;
options.threadsAllowedToBlockForConnectionMultiplier = 50;

if you use spring template, just config as follow:

<mongo:mongo host="${mongodb.server}" port="${mongodb.port}">
    <mongo:options  
      connections-per-host="${mongo.connectionsPerHost}"  
      threads-allowed-to-block-for-connection-    multiplier="${mongo.threadsAllowedToBlockForConnectionMultiplier}"  
         connect-timeout="${mongo.connectTimeout}"  
         max-wait-time="${mongo.maxWaitTime}"  
         auto-connect-retry="${mongo.autoConnectRetry}"  
         socket-keep-alive="${mongo.socketKeepAlive}"  
         socket-timeout="${mongo.socketTimeout}"     
/>

于 2013-08-15T04:13:35.087 回答
0

MongoDB 服务器启动的常用端口是 27017,您正在使用 28017。尝试将其更改为 27017,看看是否对您有帮助。

于 2013-06-05T03:57:32.580 回答