Description of your use case: (detailed description or executable reproducer, e.g. GitHub repo)
We need to override some behavior of the MongoViewService.
Current Behaviour
When we create a subclass, the mongoViewService bean remains active and all events are processed twice - once by the subclass and once by the original.
Wanted Behaviour
The original mongoViewService should be disabled when there is another bean of this type in the application.
Possible Workarounds
You can add a static BeanDefinitionRegistryPostProcessor to prevent creation of this bean:
companion object {
// Prevent creation of an extra bean for the superclass. Otherwise, all events would be processed twice.
@Bean
fun removeOriginalMongoViewServiceBeanDefinition(): BeanDefinitionRegistryPostProcessor = object : BeanDefinitionRegistryPostProcessor {
override fun postProcessBeanFactory(beanFactory: ConfigurableListableBeanFactory) {
}
override fun postProcessBeanDefinitionRegistry(registry: BeanDefinitionRegistry) {
registry.removeBeanDefinition("mongoViewService")
}
}
}
or assign the subclass to a different ProcessingGroup and avoid sending any events to the original group.
Scenario
We need to override some behavior of the
MongoViewService
.Current Behaviour
When we create a subclass, the
mongoViewService
bean remains active and all events are processed twice - once by the subclass and once by the original.Wanted Behaviour
The original
mongoViewService
should be disabled when there is another bean of this type in the application.Possible Workarounds
You can add a static
BeanDefinitionRegistryPostProcessor
to prevent creation of this bean:or assign the subclass to a different
ProcessingGroup
and avoid sending any events to the original group.