Support for matching partial generics

Closes gh-20727
This commit is contained in:
Juergen Hoeller
2024-02-15 16:51:09 +01:00
parent d4e8daaede
commit 7e67da8a26
3 changed files with 45 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -144,12 +144,16 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCan
if (cacheType) {
rbd.targetType = targetType;
}
if (descriptor.fallbackMatchAllowed() &&
(targetType.hasUnresolvableGenerics() || targetType.resolve() == Properties.class)) {
if (descriptor.fallbackMatchAllowed()) {
// Fallback matches allow unresolvable generics, e.g. plain HashMap to Map<String,String>;
// and pragmatically also java.util.Properties to any Map (since despite formally being a
// Map<Object,Object>, java.util.Properties is usually perceived as a Map<String,String>).
return true;
if (targetType.hasUnresolvableGenerics()) {
return dependencyType.isAssignableFromResolvedPart(targetType);
}
else if (targetType.resolve() == Properties.class) {
return true;
}
}
// Full check for complex generic type match...
return dependencyType.isAssignableFrom(targetType);