In Spring, what are lazily instantiated beans?
Answered
In Spring, what are lazily instantiated beans?
Best answer
The default behavior of Spring Container is to instantiate all singleton beans at startup. Lazy Initialization is a mechanism through which the Spring container can be instructed to instantiate the bean only when it gets a first client request. Lazy initialization is achieved by providing lazy-init property to true on the bean.
Lazy Initialization does not guarantee that a bean will not be instantiated at startup. A bean with lazy-init property set to true can still be instantiated at startup if it is referenced by a non-lazy-init singleton bean. In such case Spring container has to create the instance for dependency injection.