package com.xybase.demo.config;
import java.net.UnknownHostException;
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;
import com.mongodb.MongoClient;
@Configuration
public class DataSourceConfiguration {
@Bean
public MongoTemplate mongoTemplate() throws UnknownHostException {
// Define database host, port, name and user credentials if any
String host = "localhost";
int port = 27017;
String dbname = "rnd_spring_boot";
// Create MongoTemplate
MongoClient client = new MongoClient(host, port);
MongoDbFactory factory = new SimpleMongoDbFactory(client, dbname);
MongoTemplate template = new MongoTemplate(factory);
return template;
}
}