When sending the CreateAxonHealthCommand, the CommandDispatcher reports a No Handler for command: ca.xxx.yyy.CreateAxonHealthCommand message.
Here is the Aggregate
@NoArgsConstructor
public class AxonHealthHandler {
@AggregateIdentifier
private String id;
@CommandHandler
public AxonHealthHandler(CreateAxonHealthCommand command) {
if (StringUtils.isBlank(id)) {
apply(new CreateAxonHealthEvent(command.getId()));
}
}
@EventSourcingHandler
public void on(CreateAxonHealthEvent event) {
id = event.getId();
}
}
How AxonFramework discovers the classes annotated with @Aggrate?
currently, this aggragate class is in an other package as my Springboot application. In fact this aggregate is in a jar by itself.
As you already discovered, your “No handler” error should be fixed with a component scan. Besides a component scan, you could also use @Import(YourConfiguration.class) or a provide a starter with autoconfiguration.
However, I see some tiny issues with your code above.
Naming an aggregate class with Handler suffix seems kind of strange
Using generic classes such as String, UUID or long for aggregate identifiers is a brittle solution. It might be more elegant and robust to wrap the string inside a domain class such as AxonHealthId
Your id will always be null since you are checking for StringUtils.isBlank inside a constructor, so the id not yet initialized.
Your call commandGateway.send() actually uses a constant id, I am wondering why?