You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NoSuchBeanDefinitionException autowiring to collection with no matching types [SPR-6777] #11443
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
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();
}
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.
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
Activity
spring-projects-issues commentedon Jan 31, 2010
Juergen Hoeller commented
Scott, you'll need to use
@Autowired(required = false) if you are willing to accept an empty collection there. Semantically, plain@Autowiredimplies 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