I am currently writing an application that should use the MongoDB replica set. This is a Spring Boot application, and the following properties work great for connecting to a single server:
spring.data.mongodb.host=localhost spring.data.mongodb.port=27017 spring.data.mongodb.database=demo
This is absolutely normal for my local environment. But later it should work against the MongoDB replica set, so I have to provide at least 2, better than 3 replica sample sets, but how to do it with the properties?
I looked at this page: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html , but there is no explicit property for the mentioned replica sets. Providing a comma separated list of addresses:
spring.data.mongodb.host=127.0.0.1,127.0.1.1,127.0.2.1 spring.data.mongodb.uri=mongo://127.0.0.1,mongo://127.0.0.1:27018
(I tried one by one.)
This also does not work (in fact, it throws an exception that allows Spring to use the default configuration).
I also tried using the following config.xml, with no luck:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemaLocation= "http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.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/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <mongo:mongo id="replicaSetMongo" replica-set="127.0.0.1:27017,localhost:27018"/> </beans>
I know that the configs above are slightly different, but what I'm trying to do now is to get an exception that shows me that the node replica set is not available.
Any ideas, tips?
java spring-boot spring-data-mongodb mongodb
incredibleholg
source share