Class AbstractR2dbcConfiguration
java.lang.Object
org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration
- All Implemented Interfaces:
Aware
,ApplicationContextAware
@Configuration(proxyBeanMethods=false)
public abstract class AbstractR2dbcConfiguration
extends Object
implements ApplicationContextAware
Base class for Spring Data R2DBC configuration containing bean declarations that must be registered for Spring Data
R2DBC to work.
- Author:
- Mark Paluch, Jens Schauder
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract ConnectionFactory
Return a R2DBCConnectionFactory
.Customization hook to return custom converters.getDialect
(ConnectionFactory connectionFactory) Return aR2dbcDialect
for the givenConnectionFactory
.Scans the mapping base package for classes annotated withTable
.protected Collection<String>
Returns the base packages to scan for R2DBC mapped entities at startup.protected CustomConversions.StoreConversions
Returns theR2dbcDialect
-specificCustomConversions.StoreConversions
.r2dbcConverter
(R2dbcMappingContext mappingContext, R2dbcCustomConversions r2dbcCustomConversions) Creates aR2dbcConverter
using the configuredr2dbcMappingContext(Optional, R2dbcCustomConversions, RelationalManagedTypes)
R2dbcMappingContext}.Register customConverter
s in aCustomConversions
object if required.r2dbcEntityTemplate
(DatabaseClient databaseClient, ReactiveDataAccessStrategy dataAccessStrategy) org.springframework.data.relational.RelationalManagedTypes
Returns the aRelationalManagedTypes
object holding the initial entity set.r2dbcMappingContext
(Optional<org.springframework.data.relational.core.mapping.NamingStrategy> namingStrategy, R2dbcCustomConversions r2dbcCustomConversions, org.springframework.data.relational.RelationalManagedTypes r2dbcManagedTypes) Register aR2dbcMappingContext
and apply an optionalNamingStrategy
.reactiveDataAccessStrategy
(R2dbcConverter converter) Creates aReactiveDataAccessStrategy
using the configuredR2dbcConverter
.scanForEntities
(String basePackage) Scans the given base package for entities, i.e.void
setApplicationContext
(ApplicationContext applicationContext)
-
Constructor Details
-
AbstractR2dbcConfiguration
public AbstractR2dbcConfiguration()
-
-
Method Details
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
connectionFactory
Return a R2DBCConnectionFactory
. Annotate withBean
in case you want to expose aConnectionFactory
instance to theApplicationContext
.- Returns:
- the configured
ConnectionFactory
.
-
getMappingBasePackages
Returns the base packages to scan for R2DBC mapped entities at startup. Returns the package name of the configuration class' (the concrete class, not this one here) by default. So if you have acom.acme.AppConfig
extendingAbstractR2dbcConfiguration
the base package will be consideredcom.acme
unless the method is overridden to implement alternate behavior.- Returns:
- the base packages to scan for mapped
Table
classes or an empty collection to not enable scanning for entities. - Since:
- 3.0
-
r2dbcManagedTypes
@Bean public org.springframework.data.relational.RelationalManagedTypes r2dbcManagedTypes() throws ClassNotFoundExceptionReturns the aRelationalManagedTypes
object holding the initial entity set.- Returns:
- new instance of
RelationalManagedTypes
. - Throws:
ClassNotFoundException
- Since:
- 3.0
-
getDialect
Return aR2dbcDialect
for the givenConnectionFactory
. This method attempts to resolve aR2dbcDialect
fromConnectionFactoryMetadata
. Override this method to specify a dialect instead of attempting to resolve one.- Parameters:
connectionFactory
- the configuredConnectionFactory
.- Returns:
- the resolved
R2dbcDialect
. - Throws:
DialectResolver.NoDialectException
- if theR2dbcDialect
cannot be determined.
-
databaseClient
- Returns:
- must not be null.
- Throws:
IllegalArgumentException
- if any of the required args is null.
-
r2dbcEntityTemplate
@Bean public R2dbcEntityTemplate r2dbcEntityTemplate(DatabaseClient databaseClient, ReactiveDataAccessStrategy dataAccessStrategy) - Parameters:
databaseClient
- must not be null.dataAccessStrategy
- must not be null.- Returns:
- Since:
- 1.2
-
r2dbcMappingContext
@Bean public R2dbcMappingContext r2dbcMappingContext(Optional<org.springframework.data.relational.core.mapping.NamingStrategy> namingStrategy, R2dbcCustomConversions r2dbcCustomConversions, org.springframework.data.relational.RelationalManagedTypes r2dbcManagedTypes) Register aR2dbcMappingContext
and apply an optionalNamingStrategy
.- Parameters:
namingStrategy
- optionalNamingStrategy
. UseDefaultNamingStrategy.INSTANCE
as fallback.r2dbcCustomConversions
- customized R2DBC conversions.r2dbcManagedTypes
- R2DBC managed types, typically discovered throughan entity scan
.- Returns:
- must not be null.
- Throws:
IllegalArgumentException
- if any of the required args is null.
-
reactiveDataAccessStrategy
Creates aReactiveDataAccessStrategy
using the configuredR2dbcConverter
.- Parameters:
converter
- the configuredR2dbcConverter
.- Returns:
- must not be null.
- Throws:
IllegalArgumentException
- if any of the mappingContext is null.- See Also:
-
r2dbcConverter
@Bean public MappingR2dbcConverter r2dbcConverter(R2dbcMappingContext mappingContext, R2dbcCustomConversions r2dbcCustomConversions) Creates aR2dbcConverter
using the configuredr2dbcMappingContext(Optional, R2dbcCustomConversions, RelationalManagedTypes)
R2dbcMappingContext}.- Parameters:
mappingContext
- the configuredR2dbcMappingContext
.r2dbcCustomConversions
- customized R2DBC conversions.- Returns:
- must not be null.
- Throws:
IllegalArgumentException
- if any of the mappingContext is null.- Since:
- 1.2
- See Also:
-
r2dbcCustomConversions
Register customConverter
s in aCustomConversions
object if required. TheseCustomConversions
will be registered with theMappingR2dbcConverter
andr2dbcMappingContext(Optional, R2dbcCustomConversions, RelationalManagedTypes)
. Returns an emptyR2dbcCustomConversions
instance by default. OverridegetCustomConverters()
to supply custom converters.- Returns:
- must not be null.
- See Also:
-
getCustomConverters
Customization hook to return custom converters.- Returns:
- return custom converters.
-
getStoreConversions
Returns theR2dbcDialect
-specificCustomConversions.StoreConversions
.- Returns:
- the
R2dbcDialect
-specificCustomConversions.StoreConversions
.
-
getInitialEntitySet
Scans the mapping base package for classes annotated withTable
. By default, it scans for entities in all packages returned bygetMappingBasePackages()
.- Returns:
- Throws:
ClassNotFoundException
- Since:
- 3.0
- See Also:
-
scanForEntities
Scans the given base package for entities, i.e. R2DBC-specific types annotated withTable
.- Parameters:
basePackage
- must not be null.- Returns:
- a set of classes identified as entities.
- Since:
- 3.0
-