-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Autowiring of types narrows with generics does not work [SPR-11004] #15632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Juergen Hoeller commented This is covered by the fix for #15621 now, although it is actually slightly different: There it was about unresolved type variables in the target class itself whereas it is about a raw target type in this case. Anyway, it's basically covered by the same change, just with a slightly extended detection check. |
nebhale commented I just checked this against the latest set of snapshots (about 10 hours after the fix was committed) including |
Juergen Hoeller commented Ben, did that piece of code actually work before? It fails because the List<String> argument is considered a request for finding all beans of type String... and I'm pretty sure it would have done that before as well. So if I'm not missing something here, this is actually a separate issue: Juergen |
Juergen Hoeller commented FYI, in the follow-up comments to #15662, we found a regression in the last iteration. Please re-test once this is in master (which it will be in a few minutes). The general scenario above should work fine then, even if the concrete List scenario won't work (as discussed above). Juergen |
nebhale commented You're absolutely right about the Looking more deeply into my issue (it was around the @Bean
GenericType<Object> producer() {
return new GenericType<Object>();
}
@Bean
Object consumer(GenericType<String> genericType) {
return genericType;
} I'll be honest and say that I have a lot of trouble reasoning around this bit of generics, but my instinct is that this (and the declaration in |
Juergen Hoeller commented Indeed, that shouldn't work: It would have to be GenericType<?> (or <? extends Object> ) instead. That test does pass for a GenericType/GenericType<?> returning scenario for me now, against my local state (with no noteworthy changes since build 416). Juergen |
nebhale commented Agreed. I'll talk with Oliver about getting a fix to the Spring Data code. Thanks for your help. |
Oliver Drotbohm commented I've filed and fixed DATACMNS-388 for the upcoming Codd M1 and the 1.6.x bugfix branch. |
Uh oh!
There was an error while loading. Please reload this page.
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 ofList<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: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:
The text was updated successfully, but these errors were encountered: