Skip to content

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

Closed

Description

@spring-projects-issues

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:

Activity

  1. spring-projects-issues commented on Jan 31, 2010

    @spring-projects-issues
    CollaboratorAuthor

    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

  2. added
    status: declined
    type: enhancement
    in: core
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: declinedtype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions