I am new in Axon. In my project using M5 I have the following code:
private Repository axonAccountRepository;
@Autowired
public AccountCommandHandlers(Repository axonAccountRepository) {
this.axonAccountRepository = axonAccountRepository;
}
axonAccountRepository.newInstance(() -> new Account(command.getAccountId(), etc, etc)
I am getting the following error:
Description:
Parameter 0 of constructor in com.norgay.accountservice.commandHandlers.AccountCommandHandlers required a bean of type ‘org.axonframework.commandhandling.model.Repository’ that could not be found.
Action:
Consider defining a bean of type ‘org.axonframework.commandhandling.model.Repository’ in your configuration.
you may have more than one repository in your application context. In that case, Spring tries to inject one into the constructor. Apparantly, it didn’t find a suitable candidate. As far as I know, Spring resorts to named injection when there are multiple candidates. In your case, renaming the parameter to accountRepository may already help, as that’s the default name Axon gives it.
But even better, put your @CommandHandler annotations on the Aggregates themselves. That saves you from a lot of boilerplate code.
Check out the webinar series for a walk-through on how to do this: https://www.youtube.com/channel/UCz9eNSe8kY7z8DEyvv-slZg