NoHandlerForCommandException

Hi. I am new to Axon and I am having some issues with my first project.
Could you guys take a look to this question I posted in StackOverflow and let me know what you think the issue is?
Thanks.

Hi Rodeny,

I’ve just commented on your Stack Overflow issue.
I think you should replace @AggregateRoot for @Aggregate, as that will signal the Spring Boot Axon Started.
For a more thorough answer, please see my response on your Stack Overflow issue :slight_smile:

Hope this helps!

Cheers,

Steven

Hi Steven.

I just tried your recommendation and now I am getting following exception.

Command ‘com.xxx.axontest.task.CreateTaskCommand’ resulted in org.axonframework.commandhandling.model.AggregateNotFoundException(The aggregate was not found in the event store)

Hi Rodney,

Ah, see why you’re getting that.
I’m guessing you want the CreateTaskCommand to create your TaskAggregate, right?
Then I’d suggest changing the command handler for the CreateTaskCommand into a constructor.
Additionally, Axon requires a no-arg constructor, otherwise it cannot create the initial Aggregate to handle that command on.

Hope this helps you out!

Cheers,

Steven

P.S.
Updated the Stack Overflow issue as well to point that out.

That fixed the issue.
Thank you very much for your help.

PD: I am concluding in axon v3.0.6 you cannot have @COmmandHandler outside an aggregate. Is that right?

Hi Rodney,

No it’s perfectly fine to have command handlers outside of an aggregate.
As you’re running an Axon Spring Boot app with the axon-spring-boot-starter, you can just introduce a regular Spring Bean (with @Component on the class signature for example) which contains @CommandHandler annotated functions. In that scenario Axon should automatically pick it up.

Although that’s possible, typically a command would be handled in the context of one specific aggregate, so putting the command handler annotation on the aggregate directly is how I’d normally solve this.

Hope this helps!

Cheers,

Steven

That was very helpful. Thank you very much.