Skip to content

Add typesafe method to get generic bean by name with type reference #34687

Open
@quaff

Description

@quaff

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<>() {});

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: waiting-for-triageAn issue we've not yet triaged or decided on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions