Skip to content

Autowiring of types narrows with generics does not work [SPR-11004] #15632

Closed
@spring-projects-issues

Description

@spring-projects-issues

nebhale opened SPR-11004 and commented

Note that this applies to the current 4.0 snapshots, not the actual RC1 release.

Currently autowiring a bean of a type that could have a generic declaration but doesn't (e.g. List instead of List<String>) does not work when that bean should be autowired to a type that has the generic declaration (e.g. List<String>). And example is that the following wiring would not work:

@Bean
List list() {
  return new ArrayList();
}

@Bean
Object listConsumer(List<String> list) {
  return list;
}

This is useful in cases where a framework (saw spring-data-jpa) automatically creates a type (say PagedResourcesAssembler) that could be generified, but isn't. Then a consumer attempts to autowire that type, but with the generics (to quiet the compiler) and cannot get a wiring.

I've attached a test case that replicates the issue. Simply run mvm clean package && java -jar target/test.jar.


Affects: 4.0 RC1

Reference URL: f29092d#commitcomment-4368780

Attachments:

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions