Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Apr 8, 2009 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 8, 2009

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:

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We are introducing an @Lazy annotation in 3.0 M3 now. I hope that does the trick...

A default-lazy-init flag at the <beans> level will also affect component-scan instructions within its file. That should work in Spring 2.5.x already.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants