Configuration
This page aims to describe the suite of options for configuring the Command Model.
Core concepts within the Command Model are the Aggregates which are implemented. To instantiate a default Aggregate configuration you simply do the following:
Axon Configuration API
Spring Boot AutoConfiguration
Configurer configurer = DefaultConfigurer.defaultConfiguration()
.configureAggregate(GiftCard.class);
}
The
@Aggregate
annotation (in the org.axonframework.spring.stereotype
package) triggers auto configuration to set up the necessary components to use the annotated type as an aggregate. Note that only the aggregate root needs to be annotated.Axon will automatically register all the
@CommandHandler
annotated methods with the command bus and set up a repository if none is present.// ...
import org.axonframework.spring.stereotype.Aggregate;
// ...
@Aggregate
public class GiftCard {
@AggregateIdentifier
private String id;
@CommandHandler
public GiftCard(IssueCardCommand cmd) {
apply(new CardIssuedEvent(cmd.getCardId(), cmd.getAmount()));
}
}
Often times the command handler functions are placed directly on the aggregate. When this approach is taken, simply registering the Aggregate as described above is sufficient for all its command handler methods to be registered too.
External Command Handlers however do require direct registration as being a command handler, which is shown in the following sample:
Axon Configuration API
Spring Boot AutoConfiguration
Given the existence of the following Command Handler:
public class GiftCardCommandHandler {