Events Handlers no longer working after upgrade from v3 to v4

I am trying to upgrade a project from Axon 3 to Axon 4, and I cant seem to get the configuration for event handling to work.

What I have changed in the process of upgrading to version 4:

  1. Bump up Axon version from 3.4.2 to 4.1.1

  2. Include the following dependencies in the pom: axon-eventsourcing, axon-modelling, axon-messaging, axon-configuration, axon-spring, axon-test (it is a conscious decision at this stage not to use the spring auto configuration)

  3. In the class annotated with @SpringBootApplication

I have changed:

@Autowired public void configure(EventProcessingConfiguration configuration) { configuration.registerTrackingEventProcessor("normalProcessor"); }


@Autowired public void configure(EventProcessingConfigurer configurer) { configurer.registerTrackingEventProcessor("normalProcessor"); }

The event handlers are annotated with ProcessingGroup("normalProcessor")

but now when I run the application and trigger a command, I can see that the commands are handled in the aggregate, but the event handlers never get the events published from the aggregates.

Any advice on what I could be missing?

I created a gist showing the dependencies, spring context configuration and the main class

Perhaps this makes it easier to pinpoint where I might be doing it wrong?

Hi Dadepo,

if you want to use Spring without AutoConfiguration, you will need to register all your event handlers with the EventProcessingModule yourself.
You can do that by calling the registerEventHandler() method for each event handler, or otherwise, register a bean of type EventHandlerRegistrar, which will do that for you, based on the application context.

Hope this helps.

Thanks for the response Allard!

So found some time to tinker again with the configuration. Getting the event handlers to work was pretty easy by manually registering the event handlers with the EventProcessingModule…

But that is not the desired setup…the desired set up is to have the event handlers be scanned and automatically registered. I tried to achieve this by using the EventHandlerRegistrar as you suggested, but had little luck.

The configuration I had was similar to this:

> @Bean
> EventHandlerRegistrar eventHandlerRegistrar() {
>  EventHandlerRegistrar eventHandlerRegistrar = new EventHandlerRegistrar(
>  axonConfiguration(),
>  moduleConfiguration(),
>  eventProcessingModule()
>  );
>  return eventHandlerRegistrar;
> }

Which did not work. The event handlers were still not registered.

I noticed that there is a setEventHandlers method on EventHandlerRegistrar, calling that and passing the event handler works but that is not different from having to manually register the event handlers.

I think what I am missing is something as simple as AnnotationEventListenerBeanPostProcessor or @AnnotationDriven or @EnableAxon in previous versions of the framework.

Or is this exactly what EventHandlerRegistrar helps with? if yes, then more pointers to making it work would be appreciated!

Hi Dadepo,

the @EnableAxon annotation has been removed, as we do not directly support auto-configuration without Spring Boot AutoConfiguration anymore. However, it does work, by adding @Import(SpringAxonAutoConfigurer.ImportSelector.class) to one of your configuration classes. This enables automatic registration of components.

I’m not sure what your motivation is to explicitly exclude Spring Boot AutoConfiguration at this point, but we do recommend that direction.


I’m not sure what your motivation is to explicitly exclude Spring Boot AutoConfiguration at this point, but we do recommend that direction

This is because the application using Axon, that I maintain at work does not use spring boot…in-fact some of it’s configuration is still done via xml :frowning:

I appreciate the fact that spring boot is the rage nowadays, but I am guessing I won’t be the only one still maintaining and developing spring applications without the boot part - hence, in my humble option, I think it would be beneficial to still have the option of something like @EnableAxon, that eases configuration when not working with spring boot.

At work, we are currently looking at upgrading to v4, hence why it is necessary to understand the configuration options available to us without spring boot.

However, it does work, by adding @Import(SpringAxonAutoConfigurer.ImportSelector.class) to one of your configuration classes

I see, I will try this out in the coming evenings/weekend, and I will let you know how it goes! Thanks!

Hoi Allard,

So I finally got around to try out the @Import(SpringAxonAutoConfigurer.ImportSelector.class) approach you suggested.

It works, but it gets me back to where I initially started :frowning: All the components are wired up indeed, but not the event handlers :frowning:

I still had to manually call the registerEventHandler method on EventProcessingModule for each event handler… :frowning: as they are not automatically scanned and registered.

So I guess my initial question still remain:

In a spring project not using spring boot, is there a way to have the event handlers scanned and automatically registered? If I remember correctly, in previous versions of Axon, such facility was offered by AnnotationEventListenerBeanPostProcessor which finds all beans that has methods annotated with @EventHandler and subscribe them to the eventbus. This itself was later replaced by the @AnnotationDriven annotation.

How to do this? Or not possible with current version of Axon, expect one uses Spring boot?

Thanks for the help! :slight_smile:

Hi Dadepo,

As Allard mentioned earlier in this thread, registering a bean of type EventHandlerRegistrar should do the trick.

From checking the current axon-spring set up, that is also my assumption.
I’d thus suggest checking whether the combination of using the @Import(SpringAxonAutoConfigurer.ImportSelector.class) and a EventHandlerRegistrar resolve your issue.

A part from that, we have had discussion to drop auto configuration behavior from a non-auto-configuration module, and I recall the majority was in agreeance on this solution.

I’d argue it’s not because of the ‘Spring Boot’-rage, more so a reasonable separation of concerns.

Regardless, I will keep in mind your opinion on the matter as soon as we start work back on the configuration side of Axon Framework.


Hey Steven,

Thanks for the response.

I did register EventHandlerRegistrar at some point, but I noticed even with that, the handlers were not picked up automatically and I have to manually register them via the setEventHandlers method on EventHandlerRegistrar.

I can’t remember if this was done with or without @Import(SpringAxonAutoConfigurer.ImportSelector.class) . I will check this again and let you know.