Wrong bean factory method used when method names are the same in one @Configuration #25653
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: duplicate
A duplicate of another issue
type: bug
A general bug
When one
@Configuration
class have two bean factory methods with same name (but different arguments), then Spring creates both beans using only one of those factory methods.Example:
This prints:
If you try to inject qualified
printer1
bean it also will printI'm Printer 2
. So, basically the context will have 2 beans, each with own qualifier etc, but both will be created using second factory method.The solution is to rename first or second factory method to any other name to be different from name of the other method (e.g.
printer5
). Splitting@Configuration
to 2 configurations also works.As @mdeinum mentioned here the problem can be with
ConfigurationClassBeanDefinitionReader
.The text was updated successfully, but these errors were encountered: