Java tutorial
/* * MongoSpringTest - http://www.rmzone.com * * Copyright (c) 2012 Raffaele Magliocco jr. * * MongoSpringTest is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MongoSpringTest is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MongoSpringTest. If not, see <http://www.gnu.org/licenses/>. */ package com.rmzone.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.document.mongodb.MongoTemplate; import org.springframework.data.document.mongodb.config.AbstractMongoConfiguration; import com.mongodb.Mongo; /** * Spring MongoDB configuration file */ @Configuration public class SpringMongoConfig extends AbstractMongoConfiguration { @Override public @Bean Mongo mongo() throws Exception { return new Mongo("localhost"); // put your MongoDB server address. } @Override public @Bean MongoTemplate mongoTemplate() throws Exception { return new MongoTemplate(mongo(), "yourdb", "users"); } }