No 'given' events were configured for this aggregate


For the initial creation of the aggregate, I don’t have any previous events, just the starting command such as :

        .when(new RegisterHotel(....))
        .expectEvents(new HotelRegistered(...))

However, when running this test I keep getting the following error, any ideas what i’m doing wrong?

org.axonframework.repository.AggregateNotFoundException: No ‘given’ events were configured for this aggregate, nor have any events been stored.



did you put your @CommandHandler annotation for the RegisterHotel command on a constructor?



No I didnt, I’ve handled the command in my Aggregate such as…

final class Hotel extends AbstractAnnotatedAggregateRoot {

    private String id;

    public Hotel() {

    public void on(RegisterHotel cmd) {
        apply(new HotelRegistered(...));

Since it’s the command that creates a new hotel instance, it should be a constructor instead of an instance method. Replace “void on” by “Hotel” and you’re all set.

Brilliant, that works, thanks!