Related to GH-34669, but it requires the bean name matched first, and throw BeanNotOfRequiredTypeException if the bean type doesn't match required type from type reference.

Take codes in Spring Batch for example:

        @SuppressWarnings("unchecked")
        ItemReader<CustomerCredit> outputReader = (ItemReader<CustomerCredit>) applicationContext
            .getBean("outputTestReader");

I'd like it could be rewrite to:

        ItemReader<CustomerCredit> outputReader = applicationContext.getBean("outputTestReader", new ParameterizedTypeReference<>() {});

Comment From: quaff

Here is prototype: https://github.com/spring-projects/spring-framework/compare/main...quaff:spring-framework:patch-112?expand=1

I'd like to create PR if the proposal is accepted.

Comment From: quaff

Any chance target it in 7.0?

Comment From: jhoeller

This is effectively a duplicate of the just reopened #31444, so I'll close it as such. We are about to introduce getBeanProvider(ParameterizedTypeReference) for 7.0 RC1; no getBean overloads though since those do not have ResolvableType variant either.

Comment From: quaff

This is effectively a duplicate of the just reopened #31444, so I'll close it as such. We are about to introduce getBeanProvider(ParameterizedTypeReference) for 7.0 RC1; no getBean overloads though since those do not have ResolvableType variant either.

I don't think it's duplicate of #31444, this issue requests adding new variant of getBean(name, requiredType) not getBean(requiredType) (#34669), it get bean by name, and type safe for generic type. @jhoeller