Aggregate Configuration Migration
When migrating from Axon Framework 4 to Axon Framework 5, the configuration of aggregates has undergone significant changes to align with the new entity-based modeling approach. The following sections outline the key changes required to update your aggregate configurations.
EventSourcedEntityModule instead of AggregateConfigurer
The configuration of entities now uses the EventSourcedEntityModule instead of AggregateConfigurer. This aligns with the new modular configuration architecture of Axon Framework 5.
// Axon Framework 5
public void configure(EventSourcingConfigurer configurer) {
configurer.modelling().registerEventSourcedEntity(
EventSourcedEntityModule.autodetected(String.class, GiftCard.class)
);
}
One notable change in this configuration is that the identifier type of the entity must be explicitly provided.
This requirement stems from the EventSourcedEntityModule, which uses the identifier type to set up the necessary components for event sourcing and command handling.
Because the identifier type is now part of the configuration, the @AggregateIdentifier annotation on the field within your aggregate/entity is no longer required on the id property of your entity.
Spring Boot
If you have been using Spring Boot with Axon Framework 4, you will need to adjust your aggregate annotations and configuration to comply with the new standards in Axon Framework 5. The automatic detection and configuration of aggregates remains as before.
Most significant, the @Aggregate annotation is replaced by @EventSourced. The main difference between the Spring-specific @EventSourced annotation and the core @EventSourcedEntity annotation is that @EventSourced allows you to define the idType directly in the annotation (defaulting to String.class) and thus relying on the autoconfigured EventSourcedEntityModule.
@EventSourced instead of @Aggregate (Spring)
// Axon Framework 4
@Aggregate
public class GiftCard {
@AggregateIdentifier
private String giftCardId;
// ...
}
// Axon Framework 5
@EventSourced
public class GiftCard {
private String giftCardId;
// ...
}
Also, @AggregateMember is replaced by @EntityMember for child entities within an aggregate, see the multi-entity migration section for more details.
.
The @EventSourced annotation in Axon Framework 5/Spring Boot is the configuration replacement for @Aggregate, but not a fully functional/feature replacement, as attributes you may have used in AF4 (like caching, snapshotting, …) are no longer supported. Contact us if you require these use-cases.
|