Closed
Description
Oliver Drotbohm opened SPR-11419 and commented
In JavaConfig you can currently use an @Autowired(required = false) List<MyComponent> myComponents
field to access all beans of a given type to potentially hand them into a component manually instantiated in an @Bean
method.
That said, it would be nice if this pattern could be used at the @Bean
method level directly such as:
@Bean public MyOtherComponent foo(List<MyComponent> myComponents) {
…
}
This currently throws an exception if not bean of type MyComponent
can be found but could just fall back to an empty list, which is what you get with the field based approach currently.
Affects: 4.0.1
Issue Links:
- JavaConfig Bean overriding with addition [SPR-10988] #15616 JavaConfig Bean overriding with addition
- Programmatic ObjectProvider retrieval through BeanFactory API [SPR-17075] #21613 Programmatic ObjectProvider retrieval through BeanFactory API
- Accept empty Collection<Component> injection for single constructor scenarios [SPR-15338] #19901 Accept empty Collection injection for single constructor scenarios
- Consistent non-exposure of null beans in the BeanFactory API [SPR-17034] #21572 Consistent non-exposure of null beans in the BeanFactory API
- Ordered list access for BeanFactory.getBeanProvider(), superseding ObjectProvider<List> [SPR-17272] #21805 Ordered list access for BeanFactory.getBeanProvider(), superseding ObjectProvider
- Introduce Stream support in PropertySources and PropertyValues [SPR-16894] #21433 Introduce Stream support in PropertySources and PropertyValues
0 votes, 5 watchers