Description
Gordon Mohr opened SPR-5662 and commented
I'd like to be able to mark @Component-annotated
classes to be instantiated and available for autowiring only if necessary to fill any required properties.
That is, even if 'singleton' and discovered by the package-scan, they aren't instantiated until needed. ('prototype' doesn't work because I still want only one instance if referenced twice.)
A 'lazy-init' flag for the @Component
annotation would just about do the trick. Even more convenient would be some sort of 'only-if-needed' flag, which would also prevent the presence of the scan-discovered bean-definition from interfering (by being the second of the same type) with any definition explicitly included being used to satisfy a needs-one autowire-by-type situation. (Another idea along the same lines: allow specification of a recommended name for source-discovered @Components
, so they could be autowired by name, too.)
(My initial request for this sort of functionality in the forums: http://forum.springsource.org/showthread.php?p=235027#post235027 )
Affects: 2.5.6
Issue Links:
- Support use of @Primary and @Lazy during component-scanning [SPR-5629] #10300 Support use of
@Primary
and@Lazy
during component-scanning