holunda-io / camunda-bpm-taskpool

Library for pooling user tasks and process related business objects.
https://www.holunda.io/camunda-bpm-taskpool/
Apache License 2.0
66 stars 26 forks source link

Mongo View Service should be @ConditionalOnMissingBean so that we can create override its behavior #874

Closed lbilger closed 10 months ago

lbilger commented 10 months ago

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:

    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.