Skip to content

Dependency injection in @Bean method with qualifier based on parameter name doesn't work in Spring 6.1 #31685

Closed as not planned
@LogicBig

Description

@LogicBig

Following code stop working in spring-context 6.1.0.

      @Bean
       public BeanA bean1 () {
           return new BeanA("a1");
       }

       @Bean
       public BeanA bean2 () {
           return new BeanA("a2");
       }

       @Bean
       public BeanB bean3 (BeanA bean1) {
           BeanB beanB = new BeanB(bean1);
           return beanB;
       }
Error:
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.example.BeanA' available: expected single matching bean but found 2: bean1,bean2

It was working fine until spring-context 6.0.14
bean-method-parameters.zip

Didn't find any related change here:
https://github.com/spring-projects/spring-framework/wiki/What's-New-in-Spring-Framework-6.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions