Event Handler not called

Hi,

I try to figure out why @EventHandler method outside Aggregate not being called while the @CommandHandler and @EventSourcingHandler are called successfully. How do I find out the event handler is registered in the event bus?

I am using Axon-RC1

Here is the command

@Data
@AllArgsConstructor
public class CreateAccountCommand {

    @TargetAggregateIdentifier
    private String accountId;

    private String firstName;

    private String lastName;

}

Here is the code for Aggregate:

@NoArgsConstructor
@Aggregate
@Data
public class Account {

    @AggregateIdentifier
    private String accountId;

    private String firstName;

    private String lastName;

    @CommandHandler
    public Account(CreateAccountCommand command) {
        AccountCreatedEvent event = new AccountCreatedEvent(command.getAccountId(), command.getFirstName(), command.getLastName());
        apply(event);
    }

    @EventSourcingHandler
    protected void on(AccountCreatedEvent event) {
        this.accountId = event.getAccountId();
        this.firstName = event.getFirstName();
        this.lastName = event.getLastName();
 
    }
}

Here is my independent EventHandler class which is not called

@RestController
public class AccountEventHandler {

    AccountRepository accountRepository;
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    public AccountEventHandler(AccountRepository accountRepository) {
        this.accountRepository = accountRepository;
    }

    @EventHandler
    public void on(AccountCreatedEvent event) {

        AccountEntity accountEntity = new AccountEntity();
        try {
            accountEntity.setFirstName(event.getFirstName());
            accountEntity.setLastName(event.getLastName());
          
            accountRepository.save(accountEntity);
        
        }catch (Exception ex) {
            log.info(ex.getStackTrace().toString());
        }

 }
}

Thanks in advance

Sammy

Hi Sammy,

your classes seem alright. Can you share your configuration? Do you use the axon-spring-boot-starter module?

Cheers,

Allard