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:
-
ConnectionFactoryDatabaseClientEnableR2dbcRepositories
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract io.r2dbc.spi.ConnectionFactoryReturn a R2DBCConnectionFactory.Customization hook to return custom converters.getDialect(io.r2dbc.spi.ConnectionFactory connectionFactory) Return aR2dbcDialectfor 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.StoreConversionsReturns theR2dbcDialect-specificCustomConversions.StoreConversions.r2dbcConverter(R2dbcMappingContext mappingContext, R2dbcCustomConversions r2dbcCustomConversions) Creates aR2dbcConverterusing the configuredr2dbcMappingContext(Optional, R2dbcCustomConversions, RelationalManagedTypes)R2dbcMappingContext}.Register customConverters in aCustomConversionsobject if required.r2dbcEntityTemplate(DatabaseClient databaseClient, ReactiveDataAccessStrategy dataAccessStrategy) Returns the aRelationalManagedTypesobject holding the initial entity set.r2dbcMappingContext(Optional<NamingStrategy> namingStrategy, R2dbcCustomConversions r2dbcCustomConversions, RelationalManagedTypes r2dbcManagedTypes) Register aR2dbcMappingContextand apply an optionalNamingStrategy.reactiveDataAccessStrategy(R2dbcConverter converter) Creates aReactiveDataAccessStrategyusing the configuredR2dbcConverter.scanForEntities(String basePackage) Scans the given base package for entities, i.e.voidsetApplicationContext(ApplicationContext applicationContext)
-
Constructor Details
-
AbstractR2dbcConfiguration
public AbstractR2dbcConfiguration()
-
-
Method Details
-
setApplicationContext
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
connectionFactory
public abstract io.r2dbc.spi.ConnectionFactory connectionFactory()Return a R2DBCConnectionFactory. Annotate withBeanin case you want to expose aConnectionFactoryinstance 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.AppConfigextendingAbstractR2dbcConfigurationthe base package will be consideredcom.acmeunless the method is overridden to implement alternate behavior.- Returns:
- the base packages to scan for mapped
Tableclasses or an empty collection to not enable scanning for entities. - Since:
- 3.0
-
r2dbcManagedTypes
Returns the aRelationalManagedTypesobject holding the initial entity set.- Returns:
- new instance of
RelationalManagedTypes. - Throws:
ClassNotFoundException- Since:
- 3.0
-
getDialect
Return aR2dbcDialectfor the givenConnectionFactory. This method attempts to resolve aR2dbcDialectfromConnectionFactoryMetadata. 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 theR2dbcDialectcannot 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<NamingStrategy> namingStrategy, R2dbcCustomConversions r2dbcCustomConversions, RelationalManagedTypes r2dbcManagedTypes) Register aR2dbcMappingContextand apply an optionalNamingStrategy.- Parameters:
namingStrategy- optionalNamingStrategy. UseDefaultNamingStrategy.INSTANCEas 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 aReactiveDataAccessStrategyusing 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 aR2dbcConverterusing 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 customConverters in aCustomConversionsobject if required. TheseCustomConversionswill be registered with theMappingR2dbcConverterandr2dbcMappingContext(Optional, R2dbcCustomConversions, RelationalManagedTypes). Returns an emptyR2dbcCustomConversionsinstance 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
-