How to construct an Aggregate through a Command Handler?

I use spring boot and I create one aggregate:

@Aggregate
public class PaymentExecutionProcedure implements Serializable {

    protected PaymentExecutionProcedure() {
    }

    public PaymentExecutionProcedure(ProcedureRepository repository) {
    }

    @AggregateIdentifier
    private String identifier;

    @CommandHandler
    public void handle(@NotNull InitiatePaymentCommand command) throws Exception {   
         apply(command);
    }

    @EventSourcingHandler
    public void on(@NotNull InitiatePaymentEvent event) throws Exception {
        this.identifier = event.getId();
    }
}

This gives me the following exception:

'com.ISC.remittanceManagement.api.command.InitiatePaymentCommand' resulted in org.axonframework.commandhandling.CommandExecutionException(The aggregate was not found in the event store)

First off, welcome to our forum, @zeynab.

Now, on to the issue.
Luckily, the misser is rather straightforward.
You miss telling Axon Framework which command handler constructs your PaymentExecutionProcedure.

There are two ways you can tell the Framework which command handler instantiates an aggregate:

  1. Use a command handling constructor.
  2. Use a @CreationPolicy annotation.

Looking at option one, this would change your handler like so:

@CommandHandler
public PaymentExecutionProcedure(@NotNull InitiatePaymentCommand command) throws Exception {   
    apply(command);
}

If you prefer not to use constructors inside the aggregate, you can use the @CreationPolicy (for which you can find the documentation here), like so:

@CreationPolicy(AggregateCreationPolicy.ALWAYS)
@CommandHandler
public void handle(@NotNull InitiatePaymentCommand command) throws Exception {   
    apply(command);
}

By the way, the Reference Guide has this to say about the basic structure of an aggregate class.
Hope all this helps you out, @zeynab!

thank you for devices
I can improve code and correct error