I would like to know how to change my java code to support replset with spring-data and MongoDB.
I have 3 MongoDB servers running.. example:
if I do rs.status() I can see that if the db on 27017 goes down then one of the others become primary so I know that mongoDB is working right but in my java code if I try to run it I get the following error:
Exception in thread "main" org.springframework.dao.DataAccessResourceFailureE xception: can't call something : /127.0.0.1:27017/demo
Its looking only on port 27017
here is my mongodbconfig:
how do I change it to support replset?
I have 3 MongoDB servers running.. example:
Code:
./mongod --dbpath=/home/jsmith/tmp/db1 --replSet=spring --port=27017
./mongod --dbpath=/home/jsmith/tmp/db2 --replSet=spring --port=27027
./mongod --dbpath=/home/jsmith/tmp/db3 --replSet=spring --port=27037
Exception in thread "main" org.springframework.dao.DataAccessResourceFailureE xception: can't call something : /127.0.0.1:27017/demo
Its looking only on port 27017
here is my mongodbconfig:
Code:
@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 {
return new Mongo();
}
@Override
protected String getMappingBasePackage() {
return "com.xxxx.mongodb.example.domain";
}
}