Map injection fails to find bean produced with @Bean when additional method with same name exists [SPR-16999] #21537
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Kai Burjack opened SPR-16999 and commented
I wanted to use the Map<String, T> beans injection to quickly iterate over all beans implementing a given type and also to index into a bean via its name. However, we just identified a case that does not work (but probably should).
The case is, when a
@Configuration
class including a@Bean
factory method also declares another (non-@Bean
) method with the same name (but of course different parameter types) then the Map injection won't find the bean defined by the@Bean
method.Here is a test case:
This fails with injection failure of "testBeans" because Spring could not find any beans implementing Runnable. That, however, is not true. Since when removing the Map property and instead performing a manual lookup on the context via getBean("testBean") or even getBean(Runnable.class), it will find the bean.
When removing the private void testBean(boolean) method, Map injection works again.
Affects: 4.3.18, 5.0.7
Backported to: 4.3.19
The text was updated successfully, but these errors were encountered: