I'm working on a Spring Boot 3 application where I've been trying to optimize startup times by enabling lazy initialization. However, after making this change, I've encountered an issue with Kafka listeners. Specifically, the listeners stop receiving messages.
I attempted to explicitly set the @Lazy(false) annotation on the Kafka listener components, this hasn't resolved the problem. While it appears that the listener beans are created at startup (as expected with @Lazy(false)), they still do not receive any messages from Kafka.
I use Spring Boot 3.2.2 and I load my Kafka listeners from the property file like this:
spring:
cloud:
config:
allowOverride: true
overrideNone: true
overrideSystemProperties: false
function:
definition: >-
listenExample;
stream:
bindings:
listenExample-in-0:
destination: example-topic
group: example-group
consumer:
use-native-decoding: true
kafka:
bindings:
listenExample-in-0:
consumer:
enableDlq: true
dlqName: example-error-topic
dlqPartitions: 1
The component:
@Component("listenExample")
@Lazy(false)
@RequiredArgsConstructor
@Transactional
public class ExampleListener implements Consumer<Message<String>> {
@Override
public void accept(Message<String> message) {
// do something
}
}
Thank you in advance for your help!