Spring Data Document

org.springframework.data.mongodb.config
Class AbstractMongoConfiguration

java.lang.Object
  extended by org.springframework.data.mongodb.config.AbstractMongoConfiguration

@Configuration
public abstract class AbstractMongoConfiguration
extends Object

Base class for Spring Data Mongo configuration using JavaConfig.

Author:
Mark Pollack, Oliver Gierke

Constructor Summary
AbstractMongoConfiguration()
           
 
Method Summary
 CustomConversions customConversions()
          Register custom Converters in a CustomConversions object if required.
protected abstract  String getDatabaseName()
          Return the name of the database to connect to.
protected  Set<Class<?>> getInitialEntitySet()
          Scans the mapping base package for classes annotated with Document.
protected  String getMappingBasePackage()
          Return the base package to scan for mapped Documents.
protected  org.springframework.data.authentication.UserCredentials getUserCredentials()
          Return UserCredentials to be used when connecting to the MongoDB instance or null if none shall be used.
 MappingMongoConverter mappingMongoConverter()
          Creates a MappingMongoConverter using the configured mongoDbFactory() and mongoMappingContext().
abstract  Mongo mongo()
          Return the Mongo instance to connect to.
 SimpleMongoDbFactory mongoDbFactory()
          Creates a SimpleMongoDbFactory to be used by the MongoTemplate.
 MongoMappingContext mongoMappingContext()
          Creates a MongoMappingContext equipped with entity classes scanned from the mapping base package.
 MongoTemplate mongoTemplate()
          Creates a MongoTemplate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMongoConfiguration

public AbstractMongoConfiguration()
Method Detail

getDatabaseName

protected abstract String getDatabaseName()
Return the name of the database to connect to.

Returns:
must not be null.

mongo

@Bean
public abstract Mongo mongo()
                     throws Exception
Return the Mongo instance to connect to.

Returns:
Throws:
Exception

mongoTemplate

@Bean
public MongoTemplate mongoTemplate()
                            throws Exception
Creates a MongoTemplate.

Returns:
Throws:
Exception

mongoDbFactory

@Bean
public SimpleMongoDbFactory mongoDbFactory()
                                    throws Exception
Creates a SimpleMongoDbFactory to be used by the MongoTemplate. Will use the Mongo instance configured in mongo().

Returns:
Throws:
Exception
See Also:
mongo(), mongoTemplate()

getMappingBasePackage

protected String getMappingBasePackage()
Return the base package to scan for mapped Documents.

Returns:

getUserCredentials

protected org.springframework.data.authentication.UserCredentials getUserCredentials()
Return UserCredentials to be used when connecting to the MongoDB instance or null if none shall be used.

Returns:

mongoMappingContext

@Bean
public MongoMappingContext mongoMappingContext()
                                        throws ClassNotFoundException
Creates a MongoMappingContext equipped with entity classes scanned from the mapping base package.

Returns:
Throws:
ClassNotFoundException
See Also:
getMappingBasePackage()

customConversions

@Bean
public CustomConversions customConversions()
Register custom Converters in a CustomConversions object if required. These CustomConversions will be registered with the mappingMongoConverter() and mongoMappingContext(). Returns an empty CustomConversions instance by default.

Returns:
must not be null.

mappingMongoConverter

@Bean
public MappingMongoConverter mappingMongoConverter()
                                            throws Exception
Creates a MappingMongoConverter using the configured mongoDbFactory() and mongoMappingContext(). Will get customConversions() applied.

Returns:
Throws:
Exception
See Also:
customConversions(), mongoMappingContext(), mongoDbFactory()

getInitialEntitySet

protected Set<Class<?>> getInitialEntitySet()
                                     throws ClassNotFoundException
Scans the mapping base package for classes annotated with Document.

Returns:
Throws:
ClassNotFoundException
See Also:
getMappingBasePackage()

Spring Data Document

Copyright © 2012. All Rights Reserved.