兼容@Resource标记在泛型类型字段上
This commit is contained in:
@@ -570,7 +570,8 @@ public final class ResourceFactory {
|
||||
if (Modifier.isStatic(field.getModifiers())) continue;
|
||||
field.setAccessible(true);
|
||||
final Class classtype = field.getType();
|
||||
final Type genctype = field.getGenericType();
|
||||
final Type genctype = TypeToken.containsUnknownType(field.getGenericType())
|
||||
? TypeToken.getGenericType(field.getGenericType(), src.getClass()) : field.getGenericType();
|
||||
Resource rc = field.getAnnotation(Resource.class);
|
||||
if (rc == null) { //深度注入
|
||||
boolean flag = true; //是否没有重复
|
||||
|
||||
@@ -56,6 +56,27 @@ public abstract class TypeToken<T> {
|
||||
return true;
|
||||
}
|
||||
|
||||
public final static boolean containsUnknownType(final Type type) {
|
||||
if (type == null) return false;
|
||||
if (type instanceof Class) return false;
|
||||
if (type instanceof WildcardType) return true;
|
||||
if (type instanceof TypeVariable) return true;
|
||||
if (type instanceof GenericArrayType) return containsUnknownType(((GenericArrayType) type).getGenericComponentType());
|
||||
if (type instanceof ParameterizedType) {
|
||||
ParameterizedType pt = (ParameterizedType) type;
|
||||
if (containsUnknownType(pt.getRawType())) return true;
|
||||
if (containsUnknownType(pt.getOwnerType())) return true;
|
||||
Type[] ts = pt.getActualTypeArguments();
|
||||
if (ts != null) {
|
||||
for (Type t : ts) {
|
||||
if (containsUnknownType(t)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public final static Class typeToClass(final Type type) {
|
||||
if (type instanceof Class) return (Class) type;
|
||||
if (type instanceof WildcardType) return null;
|
||||
|
||||
Reference in New Issue
Block a user