我在同一台机器上运行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>
提前感谢任何输入。
答案 0 :(得分:0)
MongoDB服务器启动的常用端口是27017,您正在使用28017.尝试将其更改为27017并查看是否对您有帮助。
答案 1 :(得分:0)
试试这个。
options.connectionsPerHost = 100;
options.maxWaitTime = 2000;
options.socketKeepAlive = true;
options.threadsAllowedToBlockForConnectionMultiplier = 50;
如果你使用spring模板,只需配置如下:
<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}"
/>