Class AbstractJdbcConfiguration
java.lang.Object
org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
MyBatisJdbcConfiguration
@Configuration(proxyBeanMethods=false)
public class AbstractJdbcConfiguration
extends Object
implements org.springframework.context.ApplicationContextAware
Beans that must be registered for Spring Data JDBC to work.
- Since:
- 1.1
- Author:
- Greg Turnquist, Jens Schauder, Mark Paluch, Michael Simons, Christoph Strobl, Myeonghyeon Lee, Chirag Tailor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondataAccessStrategyBean(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations, JdbcConverter jdbcConverter, JdbcMappingContext context, Dialect dialect) Scans the mapping base package for classes annotated withTable.protected Collection<String>Returns the base packages to scan for JDBC mapped entities at startup.jdbcAggregateTemplate(org.springframework.context.ApplicationContext applicationContext, JdbcMappingContext mappingContext, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Register aJdbcAggregateTemplateas a bean for easy use in applications that need a lower level of abstraction than the normal repository abstraction.jdbcConverter(JdbcMappingContext mappingContext, org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations, RelationResolver relationResolver, JdbcCustomConversions conversions, Dialect dialect) Creates aRelationalConverterusing the configuredjdbcMappingContext(Optional, JdbcCustomConversions, RelationalManagedTypes).Register customConverters in aJdbcCustomConversionsobject if required.jdbcDialect(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations) Resolves aJDBC dialectby inspectingNamedParameterJdbcOperations.Returns the aRelationalManagedTypesobject holding the initial entity set.jdbcMappingContext(Optional<NamingStrategy> namingStrategy, JdbcCustomConversions customConversions, RelationalManagedTypes jdbcManagedTypes) Register aJdbcMappingContextand apply an optionalNamingStrategy.scanForEntities(String basePackage) Scans the given base package for entities, i.e.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) protected List<?>
-
Constructor Details
-
AbstractJdbcConfiguration
public AbstractJdbcConfiguration()
-
-
Method Details
-
getMappingBasePackages
Returns the base packages to scan for JDBC 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.AppConfigextendingAbstractJdbcConfigurationthe 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
-
jdbcManagedTypes
Returns the aRelationalManagedTypesobject holding the initial entity set.- Returns:
- new instance of
RelationalManagedTypes. - Throws:
ClassNotFoundException- Since:
- 3.0
-
jdbcMappingContext
@Bean public JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy, JdbcCustomConversions customConversions, RelationalManagedTypes jdbcManagedTypes) Register aJdbcMappingContextand apply an optionalNamingStrategy.- Parameters:
namingStrategy- optionalNamingStrategy. UseDefaultNamingStrategy.INSTANCEas fallback.customConversions- seejdbcCustomConversions().jdbcManagedTypes- JDBC managed types, typically discovered throughan entity scan.- Returns:
- must not be null.
-
jdbcConverter
@Bean public JdbcConverter jdbcConverter(JdbcMappingContext mappingContext, org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations, @Lazy RelationResolver relationResolver, JdbcCustomConversions conversions, Dialect dialect) Creates aRelationalConverterusing the configuredjdbcMappingContext(Optional, JdbcCustomConversions, RelationalManagedTypes).- Returns:
- must not be null.
- See Also:
-
jdbcCustomConversions
Register customConverters in aJdbcCustomConversionsobject if required. TheseJdbcCustomConversionswill be registered with thejdbcConverter(JdbcMappingContext, NamedParameterJdbcOperations, RelationResolver, JdbcCustomConversions, Dialect). Returns an emptyJdbcCustomConversionsinstance by default.- Returns:
- will never be null.
-
userConverters
-
jdbcAggregateTemplate
@Bean public JdbcAggregateTemplate jdbcAggregateTemplate(org.springframework.context.ApplicationContext applicationContext, JdbcMappingContext mappingContext, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Register aJdbcAggregateTemplateas a bean for easy use in applications that need a lower level of abstraction than the normal repository abstraction.- Parameters:
applicationContext- for publishing events. Must not be null.mappingContext- the mapping context to be used. Must not be null.converter- the conversions used when reading and writing from/to the database. Must not be null.- Returns:
- a
JdbcAggregateTemplate. Will never be null.
-
dataAccessStrategyBean
@Bean public DataAccessStrategy dataAccessStrategyBean(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations, JdbcConverter jdbcConverter, JdbcMappingContext context, Dialect dialect) Create aDataAccessStrategyfor reuse in theJdbcAggregateOperationsand theJdbcConverter. Override this method to register a bean of typeDataAccessStrategyif your use case requires a more specializedDataAccessStrategy.- Returns:
- will never be null.
-
jdbcDialect
@Bean public Dialect jdbcDialect(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations) Resolves aJDBC dialectby inspectingNamedParameterJdbcOperations.- Parameters:
operations- theNamedParameterJdbcOperationsallowing access to aConnection.- Returns:
- the
Dialectto be used. - Throws:
DialectResolver.NoDialectException- if theDialectcannot be determined.- Since:
- 2.0
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
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. JDBC-specific types annotated withTable.- Parameters:
basePackage- must not be null.- Returns:
- a set of classes identified as entities.
- Since:
- 3.0
-