Description
In what version(s) of Spring for Apache Kafka are you seeing this issue?
2.8,2
Describe the bug
I have a class like this:
@Autowired
private KafkaListenerEndpointRegistry registry;
@KafkaListener(
id = "#{__listener.id}",
groupId = "#{__listener.groupId}",
topics = "#{__listener.topics}",
properties = {"#{__listener.properties}"},
autoStartup = "false") // autostart is disabled, use listener.start()
Instances of the class are created this way:
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public KafkaMessageListener<?, ?> kafkaListener(String groupId,
String[] topics,
String[] properties) {
return new KafkaMessageListener<>(groupId, topics, properties);
when I create an instance of the KafkaMessageListener it starts up despite the fact that autoStartup is "false". I also tried to set
ConcurrentKafkaListenerContainerFactory.setAutoStartup(false) but without success.
I found that KafkaListenerEndpointRegistry starts my listener in this method:
private void startIfNecessary(MessageListenerContainer listenerContainer) {
if (this.contextRefreshed || listenerContainer.isAutoStartup()) {
listenerContainer.start();
}
}
because KafkaListenerEndpointRegistrar.startImmediately is true when I call appCtx.getBean(...)
I expected that when I create an instance of KafkaMessageListener it must not be started.