MongoDB Replica Set配置
参考
?
http://www.mongodb.org/display/DOCS/Replica+Set+Tutorial
?
?
本实验三个节点,启动脚本如下
?
节点1
?
?
public @BeanMongoOperations mongoTemplate(Mongo mongo) {List<ServerAddress> setList = new ArrayList<ServerAddress>();MongoOptions options = new MongoOptions();try {setList.add(new ServerAddress("localhost", 27001));setList.add(new ServerAddress("localhost", 27002));setList.add(new ServerAddress("localhost", 27003));} catch (UnknownHostException e) {e.printStackTrace();}options.autoConnectRetry = true;mongo = new Mongo(setList,options);MongoTemplate mongoTemplate = new MongoTemplate(mongo, "test");return mongoTemplate;}
?
其他就可以调用App.java操作