Spring Data MongoDB 如何使用 javaconfig 样式设置 auto-connect-retry="true"?
下面是我的配置类,有人可以告诉我吗?我想要的是如果它正在运行并且其中一个节点出现故障我希望它自动=连接到新节点
@Configuration
@EnableMongoRepositories
@ComponentScan(basePackageClasses = {MongoDBApp.class})
@PropertySource("classpath:application.properties")
public class MongoConfiguration extends AbstractMongoConfiguration {
@Override
protected String getDatabaseName() {
return "demo";
}
@Override
public Mongo mongo() throws Exception {
/**
*
* this is for a single db
*/
Mongo m = new Mongo();
m.setOptions();
// return new Mongo();
/**
*
* This is for a relset of db's
*/
return new Mongo(new ArrayList<ServerAddress>() {{ add(new ServerAddress("127.0.0.1", 27017)); add(new ServerAddress("127.0.0.1", 27027)); add(new ServerAddress("127.0.0.1", 27037)); }});
}
@Override
protected String getMappingBasePackage() {
return "com.xxx.mongodb.example.domain";
}
}