The latest spring-data-mongodb1.8.2 Official document has not been clear how to connect the replica set, I have tried many times to finally succeed, special share to everyone.
<?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.xsd Http://www.springframework.org/schema/data/mongo Http://www.springframework.org/schema/data/mongo/spring-mongo . xsd Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-be Ans.xsd "> <mongo:db-factory client-uri=" mongodb://${mongo.config.username}:${mongo.config.password}@${
Mongo.config.replica.set.address}/${mongo.config.database}?replicaset=${mongo.config.replica.set.name} "/> <bean id= "secondarypreferredreadpreference" class= "Com.mongodb.TaggableReadPreFerence. Secondarypreferredreadpreference "></bean> <bean id=" mongooperations "class=" Org.springframework.data.mongodb.core.MongoTemplate "> <constructor-arg name=" mongodbfactory "ref=" MONGODBFA Ctory "/> <property name=" readpreference "ref=" secondarypreferredreadpreference "/> </bean> < ;/beans>
mongo.config.replica.set.address=
192.168.1.199:27017,192.168.1.199:27018,192.168.1.199:27019 Mongo.config.replica.set.name=rs0 Mongo.config.database=dbname mongo.config.username=username Mongo.config.password=password