Reproduced in Spring 5.2.7.RELEASE (Spring Boot 2.3.1.RELEASE):
@Configuration
public class SomeConfig {
@Bean(name = "other")
SomeOtherBean foo() {
System.out.println("constructing SomeOtherBean");
return new SomeOtherBean();
}
@Bean(name = "foo")
SomeBean foo(@Qualifier("other") SomeOtherBean other) {
System.out.println("constructing SomeBean");
return new SomeBean(other);
}
}
With the above configuration class, SomeOtherBean is constructed twice, and SomeBean is never constructed. Why? Because the two methods have the same name. If you rename the second method to bar, everything is constructed once, as expected.
Admittedly, using the same method name is not a good idea. I just happened to have done it by accident.