I am trying to register Event handler interceptor provided as in Axon documentation but my Tests are failing because its not able to create the Bean

I am using following method from Axon documentation, to intercept Events:

@Autowired
public void configureEventProcessing(Configurer configurer) {
configurer.eventProcessing().eventProcessingConfigurer.registerHandlerInterceptor(AssetStoreKafkaEventPublisher.DEFAULT_PROCESSING_GROUP,
configuration → new TelemetryEventHandlerInterceptor());
}

But its throwing exceptions in my unit test:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘org.axonframework.config.Configurer’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

I tried mocking it my unit test but not successful. Has anyone faced this issue? any workarounds?

Maybe try to put the EventProcessingConfigurer processingConfigurer as the argument you are autowiring instead of the Configurer? You can then configure it like you are doing anyway.

Or try to put the @Autowired block into a @TestConfiguration class which is loaded as part of the @SpringBootTest.

1 Like