Skip to content
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

Even when primary candidate exists, other lazy bean candidates are instantiated [SPR-8343] #12991

spring-projects-issues opened this issue May 17, 2011 · 1 comment


Copy link

@spring-projects-issues spring-projects-issues commented May 17, 2011

Xarx opened SPR-8343 and commented

What happens:
I have a field denoted by @Autowire. There is one @Primary bean candidate for the field, the other candidates are marked as @Lazy. However, even in this case, when a primary candidate is available, all lazy candidates are instantiated during the candidate lookup process.

What should happen:
When a primary candidate exists, it should be chosen without instantiation of other lazy-init candidates.

I tried to use the @Lazy annotation to mark beans that are not to be instantiated unless realy used by the application. But this doesn't work currently.

More details:
Spring's ( DefaultListBeanFactory.doResolveDependency() internally calls findAutowireCandidates(). findAutowireCandidates() instantiates all candidate beans, but the determination whether there exists a primary candidate is done only later in doResolveDependency() - which is too late. This determination should be done earlier in findAutowireCandidates(), before the other candidates are instantiated.

Affects: 3.0.5

Issue Links:

  • #12992 Lazy-init beans are unnecessarily created during the candidate determination process ("duplicates")

4 votes, 4 watchers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant