Class MigrateSnapshotTriggerDefinitionToAnnotation

java.lang.Object
org.openrewrite.Recipe
org.openrewrite.ScanningRecipe<MigrateSnapshotTriggerDefinitionToAnnotation.Accumulator>
org.axonframework.migration.MigrateSnapshotTriggerDefinitionToAnnotation
All Implemented Interfaces:
Cloneable

public class MigrateSnapshotTriggerDefinitionToAnnotation extends org.openrewrite.ScanningRecipe<MigrateSnapshotTriggerDefinitionToAnnotation.Accumulator>
Migrates the AF4 Spring Boot snapshotting configuration to the AF5 @Snapshotting annotation.

In AF4, snapshotting required two parts:

  1. A @Bean method in a @Configuration class returning a SnapshotTriggerDefinition (e.g. new EventCountSnapshotTriggerDefinition(snapshotter, 100)).
  2. A snapshotTriggerDefinition = "beanName" attribute on the aggregate's @Aggregate annotation.
In AF5 this is replaced by @Snapshotting(afterEvents = 100) directly on the entity class.

This recipe operates in two phases:

  1. Scan – collects all @Bean methods that return a SnapshotTriggerDefinition, recording the bean name and trigger type (event-count, load-time, or custom).
  2. Edit – for each @Aggregate/@EventSourced class referencing a collected bean:
    • EventCountSnapshotTriggerDefinition → adds @Snapshotting(afterEvents = N)
    • AggregateLoadTimeSnapshotTriggerDefinition → adds @Snapshotting(afterSourcingTime = "PTxS")
    • Custom implementation → prepends a TODO(axon4to5): comment for manual review
    In all cases, the snapshotTriggerDefinition attribute is removed from the annotation. Known-type @Bean methods are deleted from the configuration class; custom ones receive a TODO(axon4to5): comment and are left in place.
Since:
5.1.1
Author:
Mateusz Nowak