Using M5

156 views
Skip to first unread message

Richard Valdivieso

unread,
Nov 29, 2016, 1:55:02 PM11/29/16
to Axon Framework Users
Hello

I was wondering if someone can help me with the following:

I have a commandhandler that is called using @CommandHandler annotation. When I use the Apply static method the event is not getting triggered. Debugging the framework it is failing in the following place


protected static AggregateLifecycle getInstance() {
AggregateLifecycle instance = CURRENT.get();
if (instance == null && CurrentUnitOfWork.isStarted()) {
UnitOfWork<?> unitOfWork = CurrentUnitOfWork.get();
Set<AggregateLifecycle> managedAggregates = unitOfWork.getResource("ManagedAggregates"); --> this is null
if (managedAggregates != null && managedAggregates.size() == 1) {
instance = managedAggregates.iterator().next();
}
}
if (instance == null) {
throw new IllegalStateException("Cannot retrieve current AggregateLifecycle; none is yet defined"); -->this is the error I am getting
}
return instance;
}


Could you please help me what I am doing wrong. The command and the event are very simple and are located in different files.

Richard

Allard Buijze

unread,
Nov 30, 2016, 4:23:23 AM11/30/16
to Axon Framework Users
Hi Richard,

the apply() method may only be used in Aggregates, whise lifecycle is managed by Axon. This exception occurs when using apply() in an @CommandHandler method on a Spring bean, for example.
Instead, put the methid on an Aggregate and simply tell Axon to manage it for you (using the Configuration API or by annotating your Agrregate Root with @Aggregate when using Spring. Axon will do the rest.

Cheers,

Allard
--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages