Skip to content

Instantly share code, notes, and snippets.

@petrukhnov
Created September 23, 2015 10:36
Show Gist options
  • Select an option

  • Save petrukhnov/46c62edb83cf342d1085 to your computer and use it in GitHub Desktop.

Select an option

Save petrukhnov/46c62edb83cf342d1085 to your computer and use it in GitHub Desktop.
@Configuration
public class MongoConfig extends AbstractMongoConfiguration {
@Value("${datasource.uri}")
private String uri;
private MongoClientURI mongoClientURI;
private Mongo mongo;
@Override
protected String getDatabaseName() {
return mongoClientURI.getDatabase();
}
@Override
public Mongo mongo() throws Exception {
mongoClientURI = new MongoClientURI(uri);
if (mongo == null) {
mongo = new MongoClient(mongoClientURI);
}
return mongo;
}
@Bean
public MongoRepositoryFactory getMongoRepositoryFactory() {
try {
return new MongoRepositoryFactory(mongoTemplate());
} catch (Exception e) {
throw new RuntimeException("error creating mongo repository factory", e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment