如何使用spring boot配置rancher mongodb集群?

时间:2016-07-05 00:00:13

标签: spring mongodb rancher

我在牧场主中添加了mongodb replicasets作为堆栈。

我已将服务的链接配置为mongodb。但是每当我在spring boot应用程序中连接到数据库时,我都会遇到这个异常:

    7/5/2016 6:57:24 AMcom.mongodb.MongoException: not talking to master and retries used up
    7/5/2016 6:57:24 AM at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:323) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:325) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:325) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:273) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:86) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:68) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBCursor._check(DBCursor.java:498) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBCursor._hasNext(DBCursor.java:621) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at com.mongodb.DBCursor.hasNext(DBCursor.java:657) ~[mongo-java-driver-2.14.2.jar!/:na]
    7/5/2016 6:57:24 AM at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1943) ~[spring-data-mongodb-1.9.1.RELEASE.jar!/:na]

我是否需要在Spring启动应用程序中添加任何其他配置才能使其正常工作。 非常感谢你。

1 个答案:

答案 0 :(得分:0)

进行这些更改,然后它将起作用。

  1. 传递完整的副本集字符串,同时连接到 mongodb,请勿传递单个服务器IP
  2. 将readPreferance更改为PrimaryPrefferred,而不是Primary