JpaConfiguration

激活条件

JpaConfiguration 激活的条件是存在 CommandBus 是 EntityManagerFactory 的bean:

  1. @ConditionalOnBean(EntityManagerFactory.class)
  2. @RegisterDefaultEntities(packages = {"org.axonframework.eventsourcing.eventstore.jpa",
  3. "org.axonframework.eventhandling.tokenstore",
  4. "org.axonframework.eventhandling.saga.repository.jpa"})
  5. @Configuration
  6. public static class JpaConfiguration {
  7. ......
  8. }

自动配置的内容

EventStorageEngine

自动配置的 EventStorageEngine 是 JpaEventStorageEngine

  1. @ConditionalOnMissingBean
  2. @Bean
  3. public EventStorageEngine eventStorageEngine(Serializer serializer,
  4. PersistenceExceptionResolver persistenceExceptionResolver,
  5. AxonConfiguration configuration,
  6. EntityManagerProvider entityManagerProvider,
  7. TransactionManager transactionManager) {
  8. return new JpaEventStorageEngine(serializer, configuration.getComponent(EventUpcaster.class), persistenceExceptionResolver, null, entityManagerProvider, transactionManager, null, null, true);
  9. }

SagaStore

自动配置的 SagaStore 是 JpaSagaStore

  1. @ConditionalOnMissingBean(SagaStore.class)
  2. @Bean
  3. public JpaSagaStore sagaStore(Serializer serializer, EntityManagerProvider entityManagerProvider) {
  4. return new JpaSagaStore(serializer, entityManagerProvider);
  5. }