In Spring, what are lazily instantiated beans?

In Spring, what are lazily instantiated beans?

Ninja Asked on 17th September 2018 in Spring.
Add Comment
1 Answer(s)
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.

Ninja Answered on 17th September 2018.
Add Comment