diff --git a/src/org/redkale/util/ResourceFactory.java b/src/org/redkale/util/ResourceFactory.java index 19eccbecc..5d312bc25 100644 --- a/src/org/redkale/util/ResourceFactory.java +++ b/src/org/redkale/util/ResourceFactory.java @@ -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; //是否没有重复 diff --git a/src/org/redkale/util/TypeToken.java b/src/org/redkale/util/TypeToken.java index 79ceaacd9..f4b27a86e 100644 --- a/src/org/redkale/util/TypeToken.java +++ b/src/org/redkale/util/TypeToken.java @@ -56,6 +56,27 @@ public abstract class TypeToken { 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;