Skip to content

Instantly share code, notes, and snippets.

@enterprisesaas
Created December 19, 2013 14:42
Show Gist options
  • Select an option

  • Save enterprisesaas/8040132 to your computer and use it in GitHub Desktop.

Select an option

Save enterprisesaas/8040132 to your computer and use it in GitHub Desktop.
Spring Java Configuration for mongo db operations
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