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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanConfigures whether to abbreviate field names for domain objects by configuring aCamelCaseAbbreviatingFieldNamingStrategyon theMongoMappingContextinstance created.protected booleanConfigure whether to automatically create indices for domain types by deriving theIndexDefinitionfrom the entity or not.protected voidconfigureClientSettings(com.mongodb.MongoClientSettings.Builder builder) ConfigureMongoClientSettingsvia itsMongoClientSettings.BuilderAPI.protected voidconfigureConverters(MongoCustomConversions.MongoConverterConfigurationAdapter converterConfigurationAdapter) Configuration hook forMongoCustomConversionscreation.Register customConverters in aCustomConversionsobject if required.protected FieldNamingStrategyConfigures aFieldNamingStrategyon theMongoMappingContextinstance created.protected abstract StringReturn 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.MongoClientSettingsReturn theMongoClientSettingsused to create the actual MongoClient.mongoMappingContext(MongoCustomConversions customConversions, MongoManagedTypes mongoManagedTypes) Creates aMongoMappingContextequipped 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.AppConfigextendingMongoConfigurationSupportthe base package will be consideredcom.acmeunless the method is overridden to implement alternate behavior.- Returns:
- the base packages to scan for mapped
Documentclasses or an empty collection to not enable scanning for entities. - Since:
- 1.10
-
mongoMappingContext
@Bean public MongoMappingContext mongoMappingContext(MongoCustomConversions customConversions, MongoManagedTypes mongoManagedTypes) Creates aMongoMappingContextequipped 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 customConverters in aCustomConversionsobject if required. TheseCustomConversionswill be registered with theMappingMongoConverterandMongoMappingContext. Returns an emptyMongoCustomConversionsinstance 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 forMongoCustomConversionscreation.- 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 aCamelCaseAbbreviatingFieldNamingStrategyon theMongoMappingContextinstance created.- Returns:
-
fieldNamingStrategy
Configures aFieldNamingStrategyon theMongoMappingContextinstance created.- Returns:
- Since:
- 1.5
-
autoIndexCreation
protected boolean autoIndexCreation()Configure whether to automatically create indices for domain types by deriving theIndexDefinitionfrom 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 theMongoClientSettingsused 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) ConfigureMongoClientSettingsvia itsMongoClientSettings.BuilderAPI.- Parameters:
builder- never null.- Since:
- 3.0
-