The @Lazy annotation tells Spring to delay creating a bean until something first asks for it. By default, singleton beans are created eagerly when the application context starts. With @Lazy, creation is deferred, which shortens startup, avoids building rarely used beans, and can break circular dependencies.
It can be placed on a @Component class, on a @Bean method, on an injection point, or on a @Configuration class.
Spring creates every singleton bean at startup, so configuration errors surface immediately. A lazy bean is created on first use, which means any failure appears later, at runtime.
Without @Lazy, the constructor message would be printed before "Application started". The annotation only changes when the singleton is created, and it is still created once and then reused.
| Placement | Effect |
|---|---|
On a @Component or @Service class | That bean is created on first request |
On a @Bean method | That bean is created on first request |
On a @Configuration class | Every @Bean method in the class is lazy |
On an injection point (@Autowired field, constructor or setter parameter) | A lazy-resolution proxy is injected, and the real bean is created on the first method call |
@Lazy(false) explicitly marks a bean as eager, which is useful inside a lazy configuration class.
When @Lazy sits on an injection point, Spring injects a proxy rather than the target bean. The target is resolved and created when you first call a method on the proxy.
The proxy needs a type it can subclass or implement. Interfaces are proxied with JDK proxies, and classes are proxied with CGLIB, so a final class with no interface cannot be lazily injected this way. If you need explicit control, ObjectProvider<T> or Provider<T> give the same laziness without a proxy and let you decide when to call getObject().
With constructor injection, two beans that depend on each other fail at startup. Since Spring Boot 2.6, circular references are prohibited by default, and the application fails with BeanCurrentlyInCreationException. Adding @Lazy to one injection point breaks the cycle, because that side receives a proxy and the real bean is resolved later.
Treat this as a workaround. A cycle usually means the responsibilities are tangled, so extracting a third class or using events is the cleaner design.
Spring Boot can enable lazy initialization application-wide:
Individual beans can opt out with @Lazy(false). This reduces startup time and memory in large applications, and it suits development and serverless cold starts. The trade-offs are real:
@Scheduled tasks, message listeners and @PostConstruct warm-up, do not start until their beans are created.For production services, many teams keep eager initialization so that failures show up during deployment, and mark only specific heavy beans as lazy.
@Lazy has an effect only on singleton beans. Prototype beans are already created on demand.@Lazy on the injection point too.No. Singleton beans are eager by default. Set spring.main.lazy-initialization=true in Spring Boot to change the default.
@Lazy delays creation of a single shared instance. A prototype scope creates a new instance on every request for the bean.
It improves startup time and memory, not steady-state speed. The first call to a lazy bean pays the creation cost.
Yes. Put it on the constructor parameter, and Spring injects a lazy-resolution proxy.
@Lazy defers bean creation until first use. Use it on specific heavy or rarely used beans, on injection points to break circular dependencies, or application-wide through spring.main.lazy-initialization, and remember that errors then appear at runtime rather than at startup.