Annotation Type Lazy
@Target({TYPE,METHOD,CONSTRUCTOR,PARAMETER,FIELD}) @Retention(RUNTIME) @Documented public @interface Lazy
Indicates whether a bean is to be lazily initialized.May be used on any class directly or indirectly annotated with
@Componentor on methods annotated with@Bean.If this annotation is not present on a
@Componentor@Beandefinition, eager initialization will occur. If present and set totrue, the@Beanor@Componentwill not be initialized until referenced by another bean or explicitly retrieved from the enclosingBeanFactory. If present and set tofalse, the bean will be instantiated on startup by bean factories that perform eager initialization of singletons.If Lazy is present on a
@Configurationclass, this indicates that all@Beanmethods within that@Configurationshould be lazily initialized. If@Lazyis present and false on a@Beanmethod within a@Lazy-annotated@Configurationclass, 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
AutowiredorInject: In that context, it leads to the creation of a lazy-resolution proxy for all affected dependencies, as an alternative to usingObjectFactoryorProvider.- Since:
- 3.0
- Author:
- Chris Beams, Juergen Hoeller
- See Also:
Primary,Bean,Configuration,Component
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description booleanvalueWhether lazy initialization should occur.
Element Detail
value
boolean value
Whether lazy initialization should occur.- Default:
- true