Need Help using Axon with Groovy!

Hi folks.

I’m working on migrating an existent app from Java to Groovy.
Previously it has been working – being in pure Java.

There’s a lot of @EventHandler-annotated methods.
Everything is wired with Spring and <axon:annotation-config />
But only those in aggregate roots are called.

  1. I have a @CompileStatic class F extends AbstractAnnotatedAggregateRoot
  • A method in class calls apply(K k)
  • There’s an @EventHandler handle(K k), and it is called
  1. I have a @CompileStatic @Component class BooDtoMapper
  • There’s an @EventHandler handle(K k)
  • It never gets called!

I’m really stuck. Even don’t understand how to debug it.

The first class is not a bean, but it’s an aggregate root. It works.

The second class is a bean, not an aggregate. It do exist in AppContext, so bean is instantiated.

It was working in Java.

All the groovy code is compiled statically.

What should I do? Please help!



you’re probably best off debugging the “AbstractAnnotationHandlerBeanPostProcessor” class. Put a breakpoint in the “postProcessAfterInitialization” method and wait for your event handler bean to pass by. The isPostProcessingCandidate() method will probably return false. The trick would be to find out why.

I am not a groovy expert, so I can’t really provide more detail than this, for now.
Good luck.


Using Groovy’s ability to access private fields, I looked at List clusters = eventBus.terminal.clusters*.members

My BooDtoMapper is there. It’s a part of ReplayingCluster. It has handle() method for K.

I have checked AbstractAnnotationHandlerBeanPostProcessor. It founds annotated method and wires the bean normally.

But events are never getting passed. Only on the aggregate root they do.

My simplest handler is a logger class:

void handle(Object event) {"EVENT: " + event);
println “EVENT: $event”

And it also can’t be called.

I feel despair.


it should be fairly easy to debug the dispatching of the handlers. If you can see it’s properly registered, just put a breakpoint in the EventBusTerminal. It will iterator over all clusters, which will iterate over each registered handler.

There must be a very obvious reason why hour handlers isn’t called. We’ll find it.




Well, for some reason I wasn’t able (and still not able) to connect Idea debugger to my app running on Tomcat with Gradle. Debugger connects, but never stops on breakpoints. So I was debugging like we were doing it a century ago: with println, copy-pasting external code in case of private modifiers.

Ugly, slow, but always works.

Finally I found the problem. It’s related both with Groovy and Axon, I think.

Groovy. Comparable interferes with @EqualsToAndHashCode, leading to a stack overflow. So the code has thrown exception during committing the changes of aggregate root: that’s why only aggregate’s handlers were called.

Axon. It ignores the failure, prints nothing to console, and just keeps working. It was really hard to notice the concrete piece of failing code. And – stack overflow exception is quite a weird one…

What was I expecting – given that I have more Akka experience. I thought it will force me to make my decisions on case of failure, like with Supervisor in Akka.

It looks like exceptions in both command and event handlers are usually ignored, in docs it’s said that you should avoid throwing exceptions in handlers.

Well, of course I should, but this one was an… exception :slight_smile:

Allard, thanks a lot for your assistance! Your advice finally moved me ahead :slight_smile:

Hi Dmitry,

did you pass a callback as parameter when sending a command? When an error occurs, the callback is notified of that error.

Glad you found the issue.