We have a spring boot application with axon framework.
In a project we have 2 Aggregates which are instantiations of the same abstract aggregate.
In short the situation is like this:
@Aggregate
abstract class Fruit {
@AggregateIdentifier
private UUID fruitId;
...
}
class Apple extends Fruit {
@CreationPolicy(CREATE_IF_MISSING)
@CommandHandler()
void myAppleCommand(AppleCommand command) {
...
apply(myAppleEvent);
}
}
class Peer extends Fruit {
@CreationPolicy(CREATE_IF_MISSING)
@CommandHandler()
void myPeerCommand(PeerCommand command) {
...
apply(myPeerEvent);
}
}
The problem is when we should end in a commandhandler myPeerCommand
or myAppleCommand
we expect a new instance of the aggregate to be created, but we get the exception: InstantiationException
.
We could get this @CreationPolicy(CREATE_IF_MISSING)
to work if we make two complete separate aggregates. But al lot of the logic is common is is all Fruit and only a small part is the specific thing for Apple or Peer.
For other problems we use the same construction but now it is for the first time with @CreationPolicy(CREATE_IF_MISSING)
on a command handler.
In our perception this should work, so the question is is this a bug or a feature?
Axon framework v4.9.4
Spring boot 3.2.6
java 21