Skip to content

Request: lazy-init or 'only-if-needed' option for stereotype @Component source-annotated component-scan definitions [SPR-5662] #10333

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions