Skip to content

NoSuchBeanDefinitionException autowiring to collection with no matching types [SPR-6777] #11443

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 Jan 28, 2010 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 28, 2010

Scott Andrews opened SPR-6777 and commented

When autowiring to a collection, if there are no beans that match the collection's type, a NoSuchBeanDefinitionException is thrown saying at least one matching bean is required. In this case, I would rather have an empty list injected then the container fail to initialize.

@Autowired
public void setFoo(List<Foo> foo) {
  assert foo.isEmpty();
}

Affects: 3.0 GA

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Scott, you'll need to use @Autowired(required = false) if you are willing to accept an empty collection there. Semantically, plain @Autowired implies that there is something found for autowiring at least - when used on a regular bean reference and also when used on a collection of bean references.

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) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants