Query handlers + Tracking Event Processor not picked up in autoconfiguration.

I am in a weird situation where when I start my (spring-boot) Axon application the command handlers are all autoconfigured just fine but none of the query handlers or tracking event processors (for my projections) are auto-configured.

This is confirmed both in the logs of the application, the DB (which does not create any tracking event processor or contain any projection state) and in the Axon Server UI (which shows no queries or tracking event processors).

I’m really at a loss as to why this is happening. What would be the initial steps to understand why this occurs or how to debug this?

Are your query handlers and event listeners defined as operations inside Spring beans? Autoconfiguration will only scan Spring beans to find annotated operations.

Marc

Yes they are defined on Spring @Service classes.

What is weird is that the same codebase used to work before. Is there any specific breakpoint you can recommend to put in when the application is starting up to better understand what exactly is going wrong?

Regards,
vab2048

For the query handlers you can put breakpoints in org.axonframework.spring.config.annotation.AnnotationQueryHandlerBeanPostProcessor. here it checks if beans have a method with a queryhandler annotation. For the tracking event processors you can check in SpringAxonAutoConfigurer.registerEventHandlerRegistrar.

Marc

Are these annotated classes in a subpackage of the one that is annotated with @SpringBootApplication? Spring Boot won’t scan the entire classpath for beans. Just the packages that you have specified, or otherwise the package in which the Application is located.

Cheers,

Okay - here is an update after some debugging (still have not resolved the issue but maybe the following info can help pin it down).

Allard - yes they are in a subpackage of the @SpringBootApplication class.

Following the advice from Marc I added some breakpoints:

  • registerEventHandlerRegistrar breakpoint
  • Here I could see the beanFactory’s beanDefinitionMap which contains everything I would expect (commands + queries). Nothing missing.- AxonAutoConfiguration.configureEventHandling breakpoint.
  • Here the state of the program is as follows:
  • EventProcessingConfigurer: everything here essentially has size 0 (see image below)
  • ApplicationContext: in here the beanFactory’s beanDefinitionMap contains all of the beans (commands + queries). Nothing missing.

I think something is going wrong with the EventProcessingConfigurer - I would expect the sizes to not be zero here?

Any tips on where next to debug?

Regards,
vab2048

After a few days banging my head against the table I have now solved the issue. It was actually nothing to do with Axon.

In attempting to get the application to startup faster I had followed the advice of some articles which have appeared in the last year (see here and here) and added the -Dspring.main.lazy-initialization=true argument to the program.

Removing this meant everything worked as expected.

Obviously now I know this should not be done when using Axon!

Allard, Marc - thanks for trying to help and apologies for the time waste.

Ironically in trying to save a few seconds of application startup time I’ve actually ended up wasting hours of time debugging :).

Hopefully if someone else in the future ends up in this position at least their google search will end up here (and they can save themselves the headache of trying to figure out what they did wrong)!

Regards,
vab2048