Class MongoConfigurationSupport
java.lang.Object
org.springframework.data.mongodb.config.MongoConfigurationSupport
- Direct Known Subclasses:
AbstractMongoClientConfiguration
,AbstractReactiveMongoConfiguration
Base class for Spring Data MongoDB to be extended for JavaConfiguration usage.
- Since:
- 2.0
- Author:
- Mark Paluch
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Configures whether to abbreviate field names for domain objects by configuring aCamelCaseAbbreviatingFieldNamingStrategy
on theMongoMappingContext
instance created.protected boolean
Configure whether to automatically create indices for domain types by deriving theIndexDefinition
from the entity or not.protected void
configureClientSettings
(com.mongodb.MongoClientSettings.Builder builder) ConfigureMongoClientSettings
via itsMongoClientSettings.Builder
API.protected void
configureConverters
(MongoCustomConversions.MongoConverterConfigurationAdapter converterConfigurationAdapter) Configuration hook forMongoCustomConversions
creation.Register customConverter
s in aCustomConversions
object if required.protected org.springframework.data.mapping.model.FieldNamingStrategy
Configures aFieldNamingStrategy
on theMongoMappingContext
instance created.protected abstract String
Return the name of the database to connect to.Scans the mapping base package for classes annotated withDocument
.protected Collection<String>
Returns the base packages to scan for MongoDB mapped entities at startup.protected com.mongodb.MongoClientSettings
Return theMongoClientSettings
used to create the actual MongoClient.mongoMappingContext
(MongoCustomConversions customConversions, MongoManagedTypes mongoManagedTypes) Creates aMongoMappingContext
equipped with entity classes scanned from the mapping base package.scanForEntities
(String basePackage) Scans the given base package for entities, i.e.
-
Constructor Details
-
MongoConfigurationSupport
public MongoConfigurationSupport()
-
-
Method Details
-
getDatabaseName
Return the name of the database to connect to.- Returns:
- must not be null.
-
getMappingBasePackages
Returns the base packages to scan for MongoDB mapped entities at startup. Will return the package name of the configuration class' (the concrete class, not this one here) by default. So if you have acom.acme.AppConfig
extendingMongoConfigurationSupport
the base package will be consideredcom.acme
unless the method is overridden to implement alternate behavior.- Returns:
- the base packages to scan for mapped
Document
classes or an empty collection to not enable scanning for entities. - Since:
- 1.10
-
mongoMappingContext
@Bean public MongoMappingContext mongoMappingContext(MongoCustomConversions customConversions, MongoManagedTypes mongoManagedTypes) Creates aMongoMappingContext
equipped with entity classes scanned from the mapping base package.- Returns:
- See Also:
-
mongoManagedTypes
- Returns:
- new instance of
MongoManagedTypes
. - Throws:
ClassNotFoundException
- Since:
- 4.0
-
customConversions
Register customConverter
s in aCustomConversions
object if required. TheseCustomConversions
will be registered with theMappingMongoConverter
andMongoMappingContext
. Returns an emptyMongoCustomConversions
instance by default.NOTE: Use
configureConverters(MongoConverterConfigurationAdapter)
to configure MongoDB native simple types and register customconverters
.- Returns:
- must not be null.
-
configureConverters
protected void configureConverters(MongoCustomConversions.MongoConverterConfigurationAdapter converterConfigurationAdapter) Configuration hook forMongoCustomConversions
creation.- Parameters:
converterConfigurationAdapter
- never null.- Since:
- 2.3
- See Also:
-
getInitialEntitySet
Scans the mapping base package for classes annotated withDocument
. By default, it scans for entities in all packages returned bygetMappingBasePackages()
.- Returns:
- Throws:
ClassNotFoundException
- See Also:
-
scanForEntities
Scans the given base package for entities, i.e. MongoDB specific types annotated withDocument
.- Parameters:
basePackage
- must not be null.- Returns:
- Throws:
ClassNotFoundException
- Since:
- 1.10
-
abbreviateFieldNames
protected boolean abbreviateFieldNames()Configures whether to abbreviate field names for domain objects by configuring aCamelCaseAbbreviatingFieldNamingStrategy
on theMongoMappingContext
instance created.- Returns:
-
fieldNamingStrategy
protected org.springframework.data.mapping.model.FieldNamingStrategy fieldNamingStrategy()Configures aFieldNamingStrategy
on theMongoMappingContext
instance created.- Returns:
- Since:
- 1.5
-
autoIndexCreation
protected boolean autoIndexCreation()Configure whether to automatically create indices for domain types by deriving theIndexDefinition
from the entity or not.- Returns:
- false by default.
INFO: As of 3.x the default is set to false; In 2.x it was true. - Since:
- 2.2
-
mongoClientSettings
protected com.mongodb.MongoClientSettings mongoClientSettings()Return theMongoClientSettings
used to create the actual MongoClient.
Override either this method, or useconfigureClientSettings(Builder)
to alter the setup.- Returns:
- never null.
- Since:
- 3.0
-
configureClientSettings
protected void configureClientSettings(com.mongodb.MongoClientSettings.Builder builder) ConfigureMongoClientSettings
via itsMongoClientSettings.Builder
API.- Parameters:
builder
- never null.- Since:
- 3.0
-