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

Filter out non-autowire candidates for calls to getBean(Class<?>) [SPR-7120] #11780

Closed
spring-projects-issues opened this issue Apr 22, 2010 · 0 comments
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

Chris Beams opened SPR-7120 and commented

Consider a scoped proxy bean of type Foo with bean name foo. If a user attempts to fetch this bean by type from the container using getBean(Foo.class), a NoSuchBeanDefinitionException will be thrown stating that there is an ambiguity because two beans of type Foo exist: [foo, scopedTarget.foo]. As it is almost certainly the user's intent to retrieve the proxy and not the target, we should filter out the scoped target before evaluating whether there is an ambiguity.

A nice way of implementing this is to simply check whether each bean definition of the matching type is an autowire candidate. If not, filter it from the list. In this way, the list in the example above will be narrowed to exactly one bean, and that bean will be returned from the call to getBean(Foo.class).


Attachments:

Referenced from: commits 3f06a92

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

1 participant