spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

ObjectFactory<List> with specified constructor args occurs error

Open qrqhuang opened this issue 3 years ago • 4 comments

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 avatar Sep 08 '22 14:09 qrqhuang

@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 avatar Sep 08 '22 15:09 snicoll

@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);
    }

qrqhuang avatar Sep 08 '22 17:09 qrqhuang

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?

snicoll avatar Sep 08 '22 18:09 snicoll

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.

spring-projects-issues avatar Sep 15 '22 19:09 spring-projects-issues

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.

spring-projects-issues avatar Sep 22 '22 19:09 spring-projects-issues