我在同一台机器上运行了 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>
提前感谢您的任何意见。