Hi.
I have a Kotlin project that uses the Axon Server as the command bus and I’m trying to add command dispatch interceptors to the existing command bus.
This is my config file:
@Configuration
class AxonConfig {
@Bean
fun trackingEventProcessorConfiguration(): TrackingEventProcessorConfiguration =
TrackingEventProcessorConfiguration
.forSingleThreadedProcessing()
.andInitialTrackingToken { obj: StreamableMessageSource<TrackedEventMessage<*>?> -> obj.createHeadToken() }
@Bean
fun configurer(
configurer: Configurer,
addNewTagToNewCategoryCommandInterceptor: AddNewTagToNewCategoryCommandInterceptor,
addNewTagToExistingCategoryCommandInterceptor: AddNewTagToExistingCategoryCommandInterceptor,
): Configurer {
// Configure event processing
configurer.eventProcessing { eventProcessingConfigurer ->
// Enable tracking event processors globally
eventProcessingConfigurer.usingTrackingEventProcessors()
}
// Configure the command bus
configurer.configureCommandBus { configuration ->
val commandBusWithInterceptors = configuration.commandBus()
// Register dispatch interceptors directly on the provided commandBus instance
commandBusWithInterceptors.registerDispatchInterceptor(addNewTagToNewCategoryCommandInterceptor)
commandBusWithInterceptors.registerDispatchInterceptor(addNewTagToExistingCategoryCommandInterceptor)
commandBusWithInterceptors // Return the customized CommandBus
}
return configurer
}
}
But this causes a stack overflow error:
ERROR 35852 --- [walletaccountant] [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountAggregateRepository': Failed to instantiate [org.axonframework.modelling.command.Repository]: Factory method 'repository' threw exception with message: null
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1355) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1185) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971) ~[spring-context-6.1.14.jar:6.1.14]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625) ~[spring-context-6.1.14.jar:6.1.14]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.3.5.jar:3.3.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.3.5.jar:3.3.5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.3.5.jar:3.3.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.3.5.jar:3.3.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.5.jar:3.3.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.5.jar:3.3.5]
at com.wa.walletaccountant.WalletAccountantApplicationKt.main(WalletAccountantApplication.kt:13) ~[main/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.axonframework.modelling.command.Repository]: Factory method 'repository' threw exception with message: null
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:178) ~[spring-beans-6.1.14.jar:6.1.14]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644) ~[spring-beans-6.1.14.jar:6.1.14]
... 19 common frames omitted
Caused by: java.lang.StackOverflowError: null
at java.base/java.lang.invoke.DirectMethodHandle.allocateInstance(DirectMethodHandle.java:501) ~[na:na]
at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.getComponent(DefaultConfigurer.java:1127) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.getComponent(Configuration.java:278) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.commandBus(Configuration.java:128) ~[axon-configuration-4.10.1.jar:4.10.1]
at com.wa.walletaccountant.common.config.AxonConfig.configurer$lambda$2(AxonConfig.kt:34) ~[main/:na]
at org.axonframework.config.Component.get(Component.java:85) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.getComponent(DefaultConfigurer.java:1132) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.getComponent(Configuration.java:278) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.commandBus(Configuration.java:128) ~[axon-configuration-4.10.1.jar:4.10.1]
at com.wa.walletaccountant.common.config.AxonConfig.configurer$lambda$2(AxonConfig.kt:34) ~[main/:na]
at org.axonframework.config.Component.get(Component.java:85) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.getComponent(DefaultConfigurer.java:1132) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.getComponent(Configuration.java:278) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.commandBus(Configuration.java:128) ~[axon-configuration-4.10.1.jar:4.10.1]
at com.wa.walletaccountant.common.config.AxonConfig.configurer$lambda$2(AxonConfig.kt:34) ~[main/:na]
at org.axonframework.config.Component.get(Component.java:85) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.getComponent(DefaultConfigurer.java:1132) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.getComponent(Configuration.java:278) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.commandBus(Configuration.java:128) ~[axon-configuration-4.10.1.jar:4.10.1]
at com.wa.walletaccountant.common.config.AxonConfig.configurer$lambda$2(AxonConfig.kt:34) ~[main/:na]
at org.axonframework.config.Component.get(Component.java:85) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.getComponent(DefaultConfigurer.java:1132) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.getComponent(Configuration.java:278) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.commandBus(Configuration.java:128) ~[axon-configuration-4.10.1.jar:4.10.1]
at com.wa.walletaccountant.common.config.AxonConfig.configurer$lambda$2(AxonConfig.kt:34) ~[main/:na]
at org.axonframework.config.Component.get(Component.java:85) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.getComponent(DefaultConfigurer.java:1132) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.getComponent(Configuration.java:278) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.commandBus(Configuration.java:128) ~[axon-configuration-4.10.1.jar:4.10.1]
at com.wa.walletaccountant.common.config.AxonConfig.configurer$lambda$2(AxonConfig.kt:34) ~[main/:na]
at org.axonframework.config.Component.get(Component.java:85) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.getComponent(DefaultConfigurer.java:1132) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.getComponent(Configuration.java:278) ~[axon-configuration-4.10.1.jar:4.10.1]
at org.axonframework.config.Configuration.commandBus(Configuration.java:128) ~[axon-configuration-4.10.1.jar:4.10.1]
at com.wa.walletaccountant.common.config.AxonConfig.configurer$lambda$2(AxonConfig.kt:34) ~[main/:na]
Any ideas?