'spring-kafka starting another container with @RefreshScope annotation

I am integrating my spring-kafka consumer with spring-cloud. Here is the bean that basically has the @KafkaListener

    @ConditionalOnMissingBean
    @Bean
    @RefreshScope
    SinkGenericKafkaConsumer<String, MessageEvent, MessageEntity> sinkGenericKafkaConsumer(final ContainerConfigProperties containerConfigProperties,
                                                                                           DataSource dataSource,
                                                                                           final SinkKafkaConsumerProperties<MessageEvent, MessageEntity> kafkaConsumerProperties) {
        return new SinkGenericKafkaConsumer<>(containerConfigProperties, kafkaConsumerProperties, dataSource);
    }

So when I make a config change and context gets refreshed I was hoping that since I am using @RefreshScope when beans are refreshed spring-kafka framework will use the new bean that gets created, but it spawns the new bean as a new container so now I have 2 containers which is not the desired thing. May be I am doing something wrong but can't figure out. Also the datasource i am injecting is not getting refreshed even though it has @ConfigurationProperties annotated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source