Configuration in SpringBoot

This extension can be added as a Spring Boot starter dependency to your project using group id org.axonframework.extensions.mongo and artifact id axon-mongo-spring-boot-starter. When using the autoconfiguration, by default the following components will be created for you automatically:

  • A MongoTransactionManager to enable transactions with Mongo.

  • A SpringMongoTransactionManager, this is the wrapped Spring mongo transaction manager, and will also be injected where applicable in other components created by the auto-config.

  • A SpringMongoTemplate, this will use a MongoDatabaseFactory that should be available. To use transaction with Mongo the collections need to be accessed in a certain way, and this component makes sure of that.

  • A MongoTokenStore, this will be used by the event processors to can keep track which events have been processed, and which segments are claimed.

  • A MongoSagaStore, this will be used to store and retrieve saga’s.

It’s also possible to autoconfigure the StorageStrategy and EventStorageEngine by setting the mongo.event-store.enabled to true. The creation of the token store and the saga store can be turned off by setting mongo.token-store.enabled or mongo.saga-store.enabled to false. It’s also possible to use a different database for the axon collections than the default the MongoDatabaseFactory uses by setting the axon.mongo.database-name property.

The relevant configuration could look like this:

spring:
  data:
    mongodb:
      uri: mongodb://localhost:27017/test
  mongo:
    database-name: axon
    token-store:
      enabled: true
    saga-store:
      enabled: false
    event-store:
      enabled: false

While test is the default database name, for the Axon collections the axon database will be used instead. The saga store will not be initialised.