Package com.impromptu.config

Source Code of com.impromptu.config.DataConfig

package com.impromptu.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.MongoFactoryBean;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.mongodb.Mongo;

@Configuration
@EnableTransactionManagement
public class DataConfig {
   
  @Autowired
  private Mongo mongo;
 
    @Bean
    public MongoFactoryBean mongo() {
      MongoFactoryBean mongo = new MongoFactoryBean();
      mongo.setHost("localhost");
      return mongo;
    }
   
    @Bean
    public MongoDbFactory mongoDbFactory() {
      return new SimpleMongoDbFactory(mongo, "impromptu-db");
    }
   
    public @Bean MongoTemplate mongoTemplate() {
      return new MongoTemplate(mongoDbFactory());
  }
}
TOP

Related Classes of com.impromptu.config.DataConfig

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.