Skip to content

Injecting beans from auto-configuration by their actual type fails #32763

@maciejwalkowiak

Description

@maciejwalkowiak

Lets assume following auto-configuration class:

@AutoConfiguration
public class PersonAutoConfiguration {

    @Bean
    PersonService personService() {
        return new PersonServiceImpl();
    }
}

Injecting personService bean by PersonServiceImpl type:

@Component
public class MyComponent {
    private final PersonServiceImpl personService;

    MyComponent(PersonServiceImpl personService) {
        this.personService = personService;
    }
}

fails with:

No qualifying bean of type '...PersonServiceImpl' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

Injecting through an interface type works without problems. Also, injecting by actual type (PersonServiceImpl) works for test classes and applicationContext.getBean(PersonServiceImpl.class) returns an actual bean.

As far as I can see only beans created through auto-configurations are affected. Beans created through regular configurations are injectable through their interfaces and actual classes.

This behaviour has not been observed in Spring Boot 2.7.4 but is reproducible from Spring Boot 3.0.0-M3 (I am not able to run build with older milestones due to missing dependencies).

Sample project that reproduces this issue coming soon.

Sample project that reproduces this issue: https://github.com/maciej-scratches/spring-boot-gh-32763 (./mvnw verify to see the failing test).

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