if (!isFactoryBean) { if (includeNonSingletons || isSingleton(beanName, mbd, dbd)) { // 这里是false就是没有匹配到bean matchFound = isTypeMatch(beanName, type, allowFactoryBeanInit); } }
...
isTypeMatch的部分源码:
1 2 3 4 5 6 7 8 9 10 11
...
elseif (!isFactoryDereference) { // 这一步返回的是false,所以继续往里面debug if (typeToMatch.isInstance(beanInstance)) { // Direct match for exposed instance? returntrue; } ...
最终返回false的地方,ClassUtils源码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
publicstaticbooleanisAssignable(Class<?> lhsType, Class<?> rhsType) { Assert.notNull(lhsType, "Left-hand side type must not be null"); Assert.notNull(rhsType, "Right-hand side type must not be null"); // 这一步返回的false,lhsType是LaunchClassLoader,rhsType是RestartClassLoader if (lhsType.isAssignableFrom(rhsType)) { returntrue; } if (lhsType.isPrimitive()) { Class<?> resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType); return (lhsType == resolvedPrimitive); } else { Class<?> resolvedWrapper = primitiveTypeToWrapperMap.get(rhsType); return (resolvedWrapper != null && lhsType.isAssignableFrom(resolvedWrapper)); } }