|
|
@ -107,8 +107,8 @@ class ConstructorResolver { |
|
|
|
* or {@code null} if none (-> use constructor argument values from bean definition) |
|
|
|
* or {@code null} if none (-> use constructor argument values from bean definition) |
|
|
|
* @return a BeanWrapper for the new instance |
|
|
|
* @return a BeanWrapper for the new instance |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public BeanWrapper autowireConstructor(final String beanName, final RootBeanDefinition mbd, |
|
|
|
public BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd, |
|
|
|
@Nullable Constructor<?>[] chosenCtors, @Nullable final Object[] explicitArgs) { |
|
|
|
@Nullable Constructor<?>[] chosenCtors, @Nullable Object[] explicitArgs) { |
|
|
|
|
|
|
|
|
|
|
|
BeanWrapperImpl bw = new BeanWrapperImpl(); |
|
|
|
BeanWrapperImpl bw = new BeanWrapperImpl(); |
|
|
|
this.beanFactory.initBeanWrapper(bw); |
|
|
|
this.beanFactory.initBeanWrapper(bw); |
|
|
@ -326,7 +326,7 @@ class ConstructorResolver { |
|
|
|
* the {@link RootBeanDefinition#isNonPublicAccessAllowed()} flag. |
|
|
|
* the {@link RootBeanDefinition#isNonPublicAccessAllowed()} flag. |
|
|
|
* Called as the starting point for factory method determination. |
|
|
|
* Called as the starting point for factory method determination. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Method[] getCandidateMethods(final Class<?> factoryClass, final RootBeanDefinition mbd) { |
|
|
|
private Method[] getCandidateMethods(Class<?> factoryClass, RootBeanDefinition mbd) { |
|
|
|
if (System.getSecurityManager() != null) { |
|
|
|
if (System.getSecurityManager() != null) { |
|
|
|
return AccessController.doPrivileged((PrivilegedAction<Method[]>) () -> |
|
|
|
return AccessController.doPrivileged((PrivilegedAction<Method[]>) () -> |
|
|
|
(mbd.isNonPublicAccessAllowed() ? |
|
|
|
(mbd.isNonPublicAccessAllowed() ? |
|
|
@ -354,7 +354,7 @@ class ConstructorResolver { |
|
|
|
* @return a BeanWrapper for the new instance |
|
|
|
* @return a BeanWrapper for the new instance |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public BeanWrapper instantiateUsingFactoryMethod( |
|
|
|
public BeanWrapper instantiateUsingFactoryMethod( |
|
|
|
final String beanName, final RootBeanDefinition mbd, @Nullable final Object[] explicitArgs) { |
|
|
|
String beanName, RootBeanDefinition mbd, @Nullable Object[] explicitArgs) { |
|
|
|
|
|
|
|
|
|
|
|
BeanWrapperImpl bw = new BeanWrapperImpl(); |
|
|
|
BeanWrapperImpl bw = new BeanWrapperImpl(); |
|
|
|
this.beanFactory.initBeanWrapper(bw); |
|
|
|
this.beanFactory.initBeanWrapper(bw); |
|
|
@ -417,13 +417,13 @@ class ConstructorResolver { |
|
|
|
factoryClass = ClassUtils.getUserClass(factoryClass); |
|
|
|
factoryClass = ClassUtils.getUserClass(factoryClass); |
|
|
|
|
|
|
|
|
|
|
|
Method[] rawCandidates = getCandidateMethods(factoryClass, mbd); |
|
|
|
Method[] rawCandidates = getCandidateMethods(factoryClass, mbd); |
|
|
|
List<Method> candidateSet = new ArrayList<>(); |
|
|
|
List<Method> candidateList = new ArrayList<>(); |
|
|
|
for (Method candidate : rawCandidates) { |
|
|
|
for (Method candidate : rawCandidates) { |
|
|
|
if (Modifier.isStatic(candidate.getModifiers()) == isStatic && mbd.isFactoryMethod(candidate)) { |
|
|
|
if (Modifier.isStatic(candidate.getModifiers()) == isStatic && mbd.isFactoryMethod(candidate)) { |
|
|
|
candidateSet.add(candidate); |
|
|
|
candidateList.add(candidate); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Method[] candidates = candidateSet.toArray(new Method[0]); |
|
|
|
Method[] candidates = candidateList.toArray(new Method[0]); |
|
|
|
AutowireUtils.sortFactoryMethods(candidates); |
|
|
|
AutowireUtils.sortFactoryMethods(candidates); |
|
|
|
|
|
|
|
|
|
|
|
ConstructorArgumentValues resolvedValues = null; |
|
|
|
ConstructorArgumentValues resolvedValues = null; |
|
|
@ -456,7 +456,7 @@ class ConstructorResolver { |
|
|
|
if (paramTypes.length >= minNrOfArgs) { |
|
|
|
if (paramTypes.length >= minNrOfArgs) { |
|
|
|
ArgumentsHolder argsHolder; |
|
|
|
ArgumentsHolder argsHolder; |
|
|
|
|
|
|
|
|
|
|
|
if (explicitArgs != null){ |
|
|
|
if (explicitArgs != null) { |
|
|
|
// Explicit arguments given -> arguments length must match exactly.
|
|
|
|
// Explicit arguments given -> arguments length must match exactly.
|
|
|
|
if (paramTypes.length != explicitArgs.length) { |
|
|
|
if (paramTypes.length != explicitArgs.length) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
@ -529,7 +529,7 @@ class ConstructorResolver { |
|
|
|
argTypes.add(arg != null ? arg.getClass().getSimpleName() : "null"); |
|
|
|
argTypes.add(arg != null ? arg.getClass().getSimpleName() : "null"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (resolvedValues != null){ |
|
|
|
else if (resolvedValues != null) { |
|
|
|
Set<ValueHolder> valueHolders = new LinkedHashSet<>(resolvedValues.getArgumentCount()); |
|
|
|
Set<ValueHolder> valueHolders = new LinkedHashSet<>(resolvedValues.getArgumentCount()); |
|
|
|
valueHolders.addAll(resolvedValues.getIndexedArgumentValues().values()); |
|
|
|
valueHolders.addAll(resolvedValues.getIndexedArgumentValues().values()); |
|
|
|
valueHolders.addAll(resolvedValues.getGenericArgumentValues()); |
|
|
|
valueHolders.addAll(resolvedValues.getGenericArgumentValues()); |
|
|
|