From fe7c28fef90d983f1043d9bca4b8bdedfb16d469 Mon Sep 17 00:00:00 2001 From: coach88 Date: Tue, 28 Jul 2015 11:07:22 +0300 Subject: [PATCH] MongoTemplate configuration with the annotation @Configuration --- spring-data-mongodb/pom.xml | 3 -- .../java/org/baeldung/config/MongoConfig.java | 28 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 spring-data-mongodb/src/main/java/org/baeldung/config/MongoConfig.java diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index 9087dbfbc7..b4abb56fd5 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -7,7 +7,6 @@ jar spring-data-mongodb - http://maven.apache.org UTF-8 @@ -18,8 +17,6 @@ 2.4.1 - - diff --git a/spring-data-mongodb/src/main/java/org/baeldung/config/MongoConfig.java b/spring-data-mongodb/src/main/java/org/baeldung/config/MongoConfig.java new file mode 100644 index 0000000000..9f9868d7d5 --- /dev/null +++ b/spring-data-mongodb/src/main/java/org/baeldung/config/MongoConfig.java @@ -0,0 +1,28 @@ +package org.baeldung.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.mongodb.config.AbstractMongoConfiguration; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; + +import com.mongodb.Mongo; +import com.mongodb.MongoClient; + +@Configuration +@EnableMongoRepositories +public class MongoConfig extends AbstractMongoConfiguration { + + @Override + protected String getDatabaseName() { + return "test"; + } + + @Override + public Mongo mongo() throws Exception { + return new MongoClient("127.0.0.1", 27017); + } + + @Override + protected String getMappingBasePackage() { + return "org.baeldung"; + } +}