Spring Boot combined with Axon Framework provides the most mature and feature-complete CQRS and Event Sourcing platform in the JVM ecosystem. This tutorial builds a complete order management system from scratch using Spring Boot 3, Axon Framework 4, and PostgreSQL, covering aggregate design, command and query handling, projections, and REST API endpoints.
Project Setup
Initialize a Spring Boot project with the required dependencies.
Configure the application properties:
Setting axonserver.enabled: false configures Axon to use JPA-based event storage instead of Axon Server, keeping the infrastructure simple for this tutorial.
Domain Events
Define domain events as immutable objects. Axon serializes these to JSON and stores them in the event store.
Commands
Commands represent intentions to change state. They target a specific aggregate instance via the @TargetAggregateIdentifier.
Order Aggregate
The aggregate handles commands, enforces invariants, and emits events. Axon manages the lifecycle: loading from event store, applying commands, and persisting new events.
Key Axon concepts:
- The constructor
@CommandHandlercreates the aggregate (first event) - Instance
@CommandHandlermethods handle subsequent commands @EventSourcingHandlermethods rebuild state from events during rehydrationAggregateLifecycle.apply()emits an event and immediately applies it
Projection (Read Model)
Projections listen to domain events and maintain denormalized read models.
Need a second opinion on your system design architecture?
I run free 30-minute strategy calls for engineering teams tackling this exact problem.
Book a Free CallQuery Handling
Axon provides a query bus for structured query dispatching.
REST Controller
Saga for Cross-Aggregate Coordination
Axon sagas manage long-running business processes that span multiple aggregates.
Integration Testing
Aggregate Testing with Axon Test Fixtures
Conclusion
Spring Boot with Axon Framework provides the most batteries-included CQRS and Event Sourcing experience available. Axon handles aggregate lifecycle management, event store persistence, saga coordination, and query routing, letting you focus on domain logic rather than infrastructure plumbing. The @CommandHandler, @EventSourcingHandler, and @EventHandler annotations make the pattern explicit and discoverable.
For teams already using Spring Boot, adding Axon is the fastest path to a production-quality CQRS/ES system. The Axon Test Fixtures provide a given-when-then DSL specifically designed for testing event-sourced aggregates, making it straightforward to verify business rules without touching a database.