Auto-register CommandHandlerInterceptor when using Spring

I’m using Axon-Framework with Spring-Boot and I’M trying to autoregister a global CommandHandlerInterceptor for commands. My assumption was, to simply create it as a bean and it is automatically discovered by Axon Framework and added to the InterceptorChain, but it doesn’t seem so.

@Component
class MyCommandHandlerInterceptor : MessageHandlerInterceptor<CommandMessage<*>> {

  override fun handle(unitOfWork: UnitOfWork<out CommandMessage<*>>, interceptorChain: InterceptorChain): Any? {
    return interceptorChain.proceed()
  }
}

It only works, when I register it manually:

@Configuration
class MyAxonConfiguration {

  @Autowired
  private lateinit var commandBus: CommandBus

  @PostConstruct
  fun registerCommandInterceptors() { 
    commandBus.registerHandlerInterceptor(MyCommandHandlerInterceptor())
  }
}

Am I doing something wrong or is this simply not implemented? If the latter: Is there a specific reason or could I provide a PR? :smiley:

The auto-configuration does not scan for beans implementing MessageHandlerInterceptor to register as interceptors in the command bus (as you have noticed). I agree that this would be an easy way to configure the interceptor, so feel free to provide a PR.

Ok thank you :+1:

Stay tuned :smiley: