package com.slodon.b2b2c.starter.mongodb;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
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.SimpleMongoClientDbFactory;

import javax.annotation.Resource;

/**
 * mongodb相关配置
 */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(SlodonMongodbProperties.class)
public class MongodbAutoConfig {

    @Resource
    private SlodonMongodbProperties slodonMongodbProperties;

    @Bean
    public MongoTemplate mongoTemplate(MongoDbFactory mongoDbFactory) {
        return new MongoTemplate(mongoDbFactory);
    }

    @Bean
    public MongoDbFactory mongoDbFactory(){
        return new SimpleMongoClientDbFactory(slodonMongodbProperties.getUri());
    }
}
