Annotation Interface Lazy
If this annotation is not present on a
eager initialization will occur. If present and set to
@Component will not be initialized until referenced by another bean or explicitly
retrieved from the enclosing
BeanFactory. If present and set to
false, the bean will be instantiated on
startup by bean factories that perform eager initialization of singletons.
If Lazy is present on a
@Configuration class, this
indicates that all
@Bean methods within that
should be lazily initialized. If
@Lazy is present and false on a
method within a
@Configuration class, this indicates
overriding the 'default lazy' behavior and that the bean should be eagerly initialized.
In addition to its role for component initialization, this annotation may also be placed
on injection points marked with
Inject: In that context, it leads to the creation of a
lazy-resolution proxy for all affected dependencies, as an alternative to using
Please note that such a lazy-resolution proxy will always be injected; if the target
dependency does not exist, you will only be able to find out through an exception on
invocation. As a consequence, such an injection point results in unintuitive behavior
for optional dependencies. For a programmatic equivalent, allowing for lazy references
with more sophistication, consider
Optional Element SummaryModifier and TypeOptional ElementDescription
booleanWhether lazy initialization should occur.
valueboolean valueWhether lazy initialization should occur.