Skip to content

@ConditionalOnBean matches beans that are not autowire candidates resulting in UnsatisfiedDependencyException when an attempt is made to inject the bean #41526

@alexey-anufriev

Description

@alexey-anufriev

Assuming the following test:

@SpringBootTest
@EnableAutoConfiguration
public class TestAutowireCandidate {

    @Test
    void test() {
    }

    @SpringBootConfiguration
    static class TestConfig {

        @Bean(autowireCandidate = false)
        Executor executor() {
            return new ThreadPoolTaskExecutorBuilder().corePoolSize(1).maxPoolSize(2).build();
        }

    }

}

And having spring-boot-starter-actuator and micrometer-core in dependencies the test fails with:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.metrics.task.TaskExecutorMetricsAutoConfiguration': 
Unsatisfied dependency expressed through method 'bindTaskExecutorsToRegistry' parameter 0: 
No qualifying bean of type 'java.util.Map<java.lang.String, java.util.concurrent.Executor>' available: 
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

Reproducer: https://github.com/alexey-anufriev/autowire-candidate-error

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions