有一个奇怪的问题,我把mongodb uri设置为。
mongodb://User:Password@machine1.uk.com:27017,machine2.uk.com:27017,machine3.ukx.com:27017/test_db_name
但是当我使用以下弹簧配置时
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<mongo:mongo />
<mongo:db-factory uri="${datamanager.host}" />
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory" />
</bean>
<mongo:repositories base-package="com.datasource.service" />
<task:annotation-driven />
我收到以下异常。请注意,machine1已删除其扩展名“uk.com”。
Caused by: com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches {serverSelectors=[ReadPreferenceServerSelector{readPreference=primary}, LatencyMinimizingServerSelector{acceptableLatencyDifference=15 ms}]}. Caused by: com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches {serverSelectors=[ReadPreferenceServerSelector{readPreference=primary}, LatencyMinimizingServerSelector{acceptableLatencyDifference=15 ms}]}. Client view of cluster state is {type=ReplicaSet, servers=[{address=machine1:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: machine1}}, {address=machine2.uk.com:27017, type=ReplicaSetSecondary, averageLatency=11.7 ms, state=Connected}, {address=machine3.uk.com:27017, type=ReplicaSetSecondary, averageLatency=11.8 ms, state=Connected}]
现在我已更新我的主机文件,将其更改为有效的IP地址,但看起来很奇怪。