Hi,
I have noticed in my project that we cannot use Spring AOP and Axon Framework together inside an Aggregate. Maybe we are doing something in an incorrect way, so if anybody could advise me, I would be really happy.
What I mean by “cannot use” is - if there we try to use a Spring AOP aspect on a @CommandHandler method, the following error will popup even though we have well initialized the aggregate and set the identifier in the command.
org.axonframework.eventsourcing.IncompatibleAggregateException: Aggregate identifier must be non-null after applying an event. Make sure the aggregate identifier is initialized at the latest when handling the creation event.
We use AOP for our custom validation on the command - workaround for this is to move the @CommandHandler method to a separate class and load the aggregate via a repository, but that causes performance issues.
I’ve prepared a very simple project that illustrates this problem - https://github.com/ultcyber/axon-demo-aop.
It is a Spring Boot 2 Web application - the way to reproduce the issue is to (excuse me for non-restful endpoints ):
- Create an aggregate via POST This will return the ID of the aggregate in point 2.
- Send a POST request to
This will result in the beforementioned error. If you take a look at the aggregate (DemoAggregate) there is an annotation @TestAnnotation which marks a method to be used by DemoAspect class to just print out the JoinPoint arguments.
If you remove the @TestAnnotation - all works without issues.
If someone could advise on this, I would be really grateful.