spring-framework
spring-framework copied to clipboard
ObjectFactory<List> with specified constructor args occurs error
ObjectProvider support a method to get bean with specified args. (#18529)
But I have a collection beans to autowired, Use ObjectProvider<List<T>>, but now it looks like the args not effect, and throw
No qualifying bean for constructor.
spring version: 4.3.25.RELEASE
@qrqhuang Unfortunately, Spring Boot 4.3.x is out of OSS support. If you manage to reproduce the problem with a supported version, please share a small sample we can run ourselves and we can have a look.
@snicoll Use spring 5.3.22, still the same error.
model
@Data
public class OrderContext {
private String orderNo;
}
component
@Component
@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
public class OrderTask {
private OrderContext orderContext;
public OrderTask(OrderContext orderContext) {
this.orderContext = orderContext;
}
}
test case. should not throw error
@Autowired
private ObjectProvider<List<OrderTask>> objectProviders;
@Test
void testProviders() {
OrderContext orderContext = new OrderContext();
orderContext.setOrderNo("222");
objectProviders.getObject(orderContext);
}
I don't understand what you're trying to achieve with a List on ObjectProvider. ObjectProvider should be used against the target bean and handle the list use case using stream. What do you expect to happen if this worked and there are multiple OrderTask in the context?
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.