Configuring an AggregateRoot-Repository in Spring Boot

Hello together,

I’m trying to move the @CommandHandler methods outside of our aggregate root classes in order
to avoid layer dependencies from the domain layer. The problem is now, how do I create a repository
for my aggregate root in this new command handling classes.

In the axon-spring-boot-starter dependency there is the following example:


public class SomeAggregateRoot
        extends AbstractAnnotatedAggregateRoot<SomeIDType> {
    private SomeIDType id;


public final class SomeClassUsingRespository {
    private Repository<SomeAggregateRoot> repository;

In axon 3.2 there is no longer a class AbstractAnnotatedAggregateRoot and @MetaInfServices is not included. What is the
right way to do this now ? Why does this work if the @CommandHandler methods are inside my aggregate root ?

In the axon trader example, there is bean defined for the repository:

public Repository<Transaction> transactionRepository() {
   EventCountSnapshotTriggerDefinition triggerDefinition = new EventCountSnapshotTriggerDefinition(snapshotter, 50);
   CachingEventSourcingRepository<Transaction> repository = new CachingEventSourcingRepository<>(transactionAggregateFactory(), eventStore, cache, triggerDefinition);

   return repository;

But in this really needed ? If yes is there an example of axon 3.2 with some explanation what to do ?

Thanks in advance,


Ok I found the solution myself, sometimes the easiest way works :slight_smile:

public class DomainRepositoryConfig
 public Repository<ProductProvider> productProviderRepository(EventStore eventStore)
 return new EventSourcingRepository<>(ProductProvider.class, eventStore);

  • Benjamin