environment: spring boot 2.6.10
define a demo app with following configuration class:
@Configuration
public class DemoConfig {
@Bean("aaa")
public String foo() {
return "foo";
}
@Bean("aaa")
public String bar() {
return "bar";
}
}
should be: BeanDefinitionOverrideException is: bean named "aaa" added to bean context (with value "foo"), method bar() never added to bean definition
debugging shows a return statement here, that seems to the cuprit.
https://github.com/spring-projects/spring-framework/blob/8fe6a9f5374a0ed56ba4e1e9b2287d581009719e/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java#L212-L219
Comment From: snicoll
Thanks for the report and sorry it took so long.
Your example shows that the methods have the bean same name in the same configuration class so the container considers them to be two factory methods for the same bean where the container should choose which one to pick based on the arguments.
As you've noticed, this is really confusing and we've decided to deprecate this behavior, see https://github.com/spring-projects/spring-framework/issues/31073