Spring boot eagerly initialize some beans

Viewed 35

I want to enable lazy initialization for my spring boot application to improve the startup time. But once I do that this causes some problems. E.g. my KafkaListeners are also not initialized and will not receive any messages. Can I enable lazy initialization, but eagerly initialize some specific beans?

2 Answers

To be able to make a specific bean eager initialized, I found the annotation org.springframework.context.annotation.Lazy(false). This made it work for me.

By default all beans are initialized eagerly in order to have consistent application context. You could initialize some specific beans lazily with @Lazy.

Related