Created
September 23, 2015 10:36
-
-
Save petrukhnov/46c62edb83cf342d1085 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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