Package com.xybase.demo.config

Source Code of com.xybase.demo.config.DataSourceConfiguration

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;
  }

}
TOP

Related Classes of com.xybase.demo.config.DataSourceConfiguration

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.