|
|
|
@ -724,19 +724,18 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac |
|
|
|
int minNrOfArgs = |
|
|
|
int minNrOfArgs = |
|
|
|
(mbd.hasConstructorArgumentValues() ? mbd.getConstructorArgumentValues().getArgumentCount() : 0); |
|
|
|
(mbd.hasConstructorArgumentValues() ? mbd.getConstructorArgumentValues().getArgumentCount() : 0); |
|
|
|
Method[] candidates = ReflectionUtils.getUniqueDeclaredMethods(factoryClass); |
|
|
|
Method[] candidates = ReflectionUtils.getUniqueDeclaredMethods(factoryClass); |
|
|
|
for (Method factoryMethod : candidates) { |
|
|
|
for (Method candidate : candidates) { |
|
|
|
if (Modifier.isStatic(factoryMethod.getModifiers()) == isStatic && |
|
|
|
if (Modifier.isStatic(candidate.getModifiers()) == isStatic && mbd.isFactoryMethod(candidate) && |
|
|
|
factoryMethod.getName().equals(mbd.getFactoryMethodName()) && |
|
|
|
candidate.getParameterCount() >= minNrOfArgs) { |
|
|
|
factoryMethod.getParameterCount() >= minNrOfArgs) { |
|
|
|
|
|
|
|
// Declared type variables to inspect?
|
|
|
|
// Declared type variables to inspect?
|
|
|
|
if (factoryMethod.getTypeParameters().length > 0) { |
|
|
|
if (candidate.getTypeParameters().length > 0) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
// Fully resolve parameter names and argument values.
|
|
|
|
// Fully resolve parameter names and argument values.
|
|
|
|
Class<?>[] paramTypes = factoryMethod.getParameterTypes(); |
|
|
|
Class<?>[] paramTypes = candidate.getParameterTypes(); |
|
|
|
String[] paramNames = null; |
|
|
|
String[] paramNames = null; |
|
|
|
ParameterNameDiscoverer pnd = getParameterNameDiscoverer(); |
|
|
|
ParameterNameDiscoverer pnd = getParameterNameDiscoverer(); |
|
|
|
if (pnd != null) { |
|
|
|
if (pnd != null) { |
|
|
|
paramNames = pnd.getParameterNames(factoryMethod); |
|
|
|
paramNames = pnd.getParameterNames(candidate); |
|
|
|
} |
|
|
|
} |
|
|
|
ConstructorArgumentValues cav = mbd.getConstructorArgumentValues(); |
|
|
|
ConstructorArgumentValues cav = mbd.getConstructorArgumentValues(); |
|
|
|
Set<ConstructorArgumentValues.ValueHolder> usedValueHolders = new HashSet<>(paramTypes.length); |
|
|
|
Set<ConstructorArgumentValues.ValueHolder> usedValueHolders = new HashSet<>(paramTypes.length); |
|
|
|
@ -753,9 +752,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Class<?> returnType = AutowireUtils.resolveReturnTypeForFactoryMethod( |
|
|
|
Class<?> returnType = AutowireUtils.resolveReturnTypeForFactoryMethod( |
|
|
|
factoryMethod, args, getBeanClassLoader()); |
|
|
|
candidate, args, getBeanClassLoader()); |
|
|
|
uniqueCandidate = (commonType == null && returnType == factoryMethod.getReturnType() ? |
|
|
|
uniqueCandidate = (commonType == null && returnType == candidate.getReturnType() ? |
|
|
|
factoryMethod : null); |
|
|
|
candidate : null); |
|
|
|
commonType = ClassUtils.determineCommonAncestor(returnType, commonType); |
|
|
|
commonType = ClassUtils.determineCommonAncestor(returnType, commonType); |
|
|
|
if (commonType == null) { |
|
|
|
if (commonType == null) { |
|
|
|
// Ambiguous return types found: return null to indicate "not determinable".
|
|
|
|
// Ambiguous return types found: return null to indicate "not determinable".
|
|
|
|
@ -769,8 +768,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
uniqueCandidate = (commonType == null ? factoryMethod : null); |
|
|
|
uniqueCandidate = (commonType == null ? candidate : null); |
|
|
|
commonType = ClassUtils.determineCommonAncestor(factoryMethod.getReturnType(), commonType); |
|
|
|
commonType = ClassUtils.determineCommonAncestor(candidate.getReturnType(), commonType); |
|
|
|
if (commonType == null) { |
|
|
|
if (commonType == null) { |
|
|
|
// Ambiguous return types found: return null to indicate "not determinable".
|
|
|
|
// Ambiguous return types found: return null to indicate "not determinable".
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
@ -1281,7 +1280,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac |
|
|
|
* from the bean definition. |
|
|
|
* from the bean definition. |
|
|
|
* @param beanName the name of the bean |
|
|
|
* @param beanName the name of the bean |
|
|
|
* @param mbd the bean definition for the bean |
|
|
|
* @param mbd the bean definition for the bean |
|
|
|
* @param bw BeanWrapper with bean instance |
|
|
|
* @param bw the BeanWrapper with bean instance |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void populateBean(String beanName, RootBeanDefinition mbd, @Nullable BeanWrapper bw) { |
|
|
|
protected void populateBean(String beanName, RootBeanDefinition mbd, @Nullable BeanWrapper bw) { |
|
|
|
if (bw == null) { |
|
|
|
if (bw == null) { |
|
|
|
@ -1370,7 +1369,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac |
|
|
|
* @param beanName the name of the bean we're wiring up. |
|
|
|
* @param beanName the name of the bean we're wiring up. |
|
|
|
* Useful for debugging messages; not used functionally. |
|
|
|
* Useful for debugging messages; not used functionally. |
|
|
|
* @param mbd bean definition to update through autowiring |
|
|
|
* @param mbd bean definition to update through autowiring |
|
|
|
* @param bw BeanWrapper from which we can obtain information about the bean |
|
|
|
* @param bw the BeanWrapper from which we can obtain information about the bean |
|
|
|
* @param pvs the PropertyValues to register wired objects with |
|
|
|
* @param pvs the PropertyValues to register wired objects with |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void autowireByName( |
|
|
|
protected void autowireByName( |
|
|
|
@ -1404,7 +1403,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac |
|
|
|
* behavior for bigger applications. |
|
|
|
* behavior for bigger applications. |
|
|
|
* @param beanName the name of the bean to autowire by type |
|
|
|
* @param beanName the name of the bean to autowire by type |
|
|
|
* @param mbd the merged bean definition to update through autowiring |
|
|
|
* @param mbd the merged bean definition to update through autowiring |
|
|
|
* @param bw BeanWrapper from which we can obtain information about the bean |
|
|
|
* @param bw the BeanWrapper from which we can obtain information about the bean |
|
|
|
* @param pvs the PropertyValues to register wired objects with |
|
|
|
* @param pvs the PropertyValues to register wired objects with |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void autowireByType( |
|
|
|
protected void autowireByType( |
|
|
|
|