Class JdbcAutoConfiguration
Registers a ConnectionProvider, a TokenSchema, a TokenStore, and a
PersistenceExceptionResolver when a DataSource bean is present in the application context.
All beans are conditional on the absence of user-supplied alternatives, so they can be overridden by providing
custom beans of the same types.
This configuration runs after JpaAutoConfiguration to allow JPA-specific beans (such as a JPA-based
PersistenceExceptionResolver) to take precedence.
- Since:
- 3.1
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionJdbcAutoConfiguration(TokenStoreProperties tokenStoreProperties) Creates a newJdbcAutoConfigurationwith the givenTokenStoreProperties. -
Method Summary
Modifier and TypeMethodDescriptionconnectionProvider(DataSource dataSource) Provides aConnectionProviderbacked by the application'sDataSource.Provides aPersistenceExceptionResolverthat detects duplicate key violations from JDBCSQLIntegrityConstraintViolationExceptionexceptions.Provides a defaultTokenSchemadescribing the table and column names used by the JDBC token store.tokenStore(DataSource dataSource, TokenSchema tokenSchema, tools.jackson.databind.ObjectMapper defaultAxonObjectMapper) Provides a JDBC-backedTokenStorefor tracking event processor token persistence.
-
Constructor Details
-
JdbcAutoConfiguration
Creates a newJdbcAutoConfigurationwith the givenTokenStoreProperties.- Parameters:
tokenStoreProperties- properties used to configure the JDBC-backedTokenStore
-
-
Method Details
-
connectionProvider
Provides aConnectionProviderbacked by the application'sDataSource.Uses
SpringDataSourceConnectionProvider, which is aware of Spring's transaction management and returns the connection bound to the active transaction when one is present.- Parameters:
dataSource- the data source to obtain connections from- Returns:
- a connection provider for use in JDBC-based Axon components
-
tokenSchema
@Bean @ConditionalOnMissingBean({TokenStore.class,TokenSchema.class}) public TokenSchema tokenSchema()Provides a defaultTokenSchemadescribing the table and column names used by the JDBC token store.Only created when neither a
TokenStorenor aTokenSchemabean is already present, because a customTokenStoremay use its own schema definition.- Returns:
- a default
TokenSchema
-
tokenStore
@Bean @ConditionalOnMissingBean(TokenStore.class) public TokenStore tokenStore(DataSource dataSource, TokenSchema tokenSchema, tools.jackson.databind.ObjectMapper defaultAxonObjectMapper) Provides a JDBC-backedTokenStorefor tracking event processor token persistence.Uses a
JdbcTransactionalExecutorProviderto participate in JDBC transactions and aJacksonConverterto serialize tokens as JSON.- Parameters:
dataSource- the data source used to execute token store queriestokenSchema- the schema describing the token store table layoutdefaultAxonObjectMapper- the object mapper used to serialize tokens- Returns:
- a configured
JdbcTokenStore
-
persistenceExceptionResolver
Provides aPersistenceExceptionResolverthat detects duplicate key violations from JDBCSQLIntegrityConstraintViolationExceptionexceptions.Conditional on the absence of an existing
PersistenceExceptionResolverbean, sinceJpaAutoConfigurationmay already register one when JPA is on the classpath.- Returns:
- a
JdbcSQLErrorCodesResolverinstance
-