Configurability of annotations in Axon


I’m in the process of integrating axon framework into seedstack ( to add cqrs capabilities thanks to axon.
Seedstack takes advantage of Domain-Driven Design to build great Java microservices and applications
by offering a clean API/Specs around DDD tacticals building blocks in one hand and a robust implementation
of that specs in the other hand (mainly guice based via nuun kernel).

It would be great if axon could add a way to configure the annotations it uses to declare its own building blocks to allow clean integration into other stacks.

  • @AggregateIdentifier (mandatory): for instance today javax.persistence.Id is also a trigger to identify the identifier of an aggregate, we could configure ours.

  • @TargetAggregateIdentifier (optional)

  • @TargetAggregateVersion (optional)

The external annotation could be configured via the Configuration API.

   Configurer configurer = DefaultConfigurer.defaultConfiguration();

I can imagine propose a PR when I understand where to make the modification, if this is something you estimate OK.

Thank you


Epo J.

Hi Epo,

strictly speaking, it is already possible to change this behavior. However, it’s not as easy as just saying “look at a different annotation”, yet. It is the AggregateModel class that described the structure of the aggregate, and also defines how the identifyer should be retrieved.

By default, Axon uses the AnnotatedAggregateMetaModelFactory to create these models. However, you can define your own implementation and register it with the Configurer (as a component of type AggregateMetaModelFactory). Axon will then use that implementation instead. The AnnotatedAggregateMetaModelFactory is a relatively new class and hasn’t been designed for reuse, yet.

Alternatively, in certain cases you might be able to meta-annotate an annotation. If you can do that, you can put the @AggregateIdentifier annotation on the annotation that you would like to put on the field. Note that annotations that don’t exist on the classpath at runtime are simply ignored. That means putting an Axon annotation on an annotation of another framework, doesn’t force any users of that other framework to also include Axon.