DEV Community

Lazy Beans in Spring

eidher on October 05, 2020

Beans are created on startup when the application context is created (eagerly). But, lazy beans are created the first time they are used. Its use i...
Collapse
 
kriska profile image
Kristina Gocheva

You've described very briefly the lazy annotation and its effect. I would like to understand why you said that it's usages is not recommended. Some additional examples would be helpful.

Collapse
 
eidher profile image
eidher

I won't recommend its use because we could mask issues, getting them in run time instead of startup time (out of memory errors, misconfigurations, or class-definition-found errors). Besides, triggering bean creation on demand will increase the latency of HTTP requests impacting load balancing and autoscale in cloud environments.