Created
December 19, 2013 14:42
-
-
Save enterprisesaas/8040132 to your computer and use it in GitHub Desktop.
Spring Java Configuration for mongo db operations
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
| package config; | |
| import com.mongodb.MongoClient; | |
| import concepts.UserMongoDao; | |
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.context.annotation.Configuration; | |
| import org.springframework.data.mongodb.MongoDbFactory; | |
| import org.springframework.data.mongodb.core.MongoTemplate; | |
| import org.springframework.data.mongodb.core.SimpleMongoDbFactory; | |
| @Configuration | |
| public class MongoConfig { | |
| @Bean | |
| public MongoDbFactory mongoDbFactory() throws Exception { | |
| return new SimpleMongoDbFactory(new MongoClient(), "adaptJavaCore"); | |
| } | |
| @Bean | |
| public MongoTemplate mongoTemplate() throws Exception { | |
| MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory()); | |
| return mongoTemplate; | |
| } | |
| @Bean | |
| public UserMongoDao userMongoDao() throws Exception { | |
| UserMongoDao userMongoDao = new UserMongoDao(); | |
| userMongoDao.setMongoOperations(mongoTemplate()); | |
| return userMongoDao; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment