spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java
/**
	 * Create an array of arguments to invoke a constructor or factory method,
	 * given the resolved constructor argument values.
	 */
Create an array of arguments to invoke a constructor or factory method,
given the resolved constructor argument values.
Create an array of arguments to invoke a constructor or factory method given the resolved constructor argument values .
private ArgumentsHolder createArgumentArray(
			String beanName, RootBeanDefinition mbd, @Nullable ConstructorArgumentValues resolvedValues,
			BeanWrapper bw, Class<?>[] paramTypes, @Nullable String[] paramNames, Executable executable,
			boolean autowiring, boolean fallback) throws UnsatisfiedDependencyException {
		TypeConverter customConverter = this.beanFactory.getCustomTypeConverter();
		TypeConverter converter = (customConverter != null ? customConverter : bw);
		ArgumentsHolder args = new ArgumentsHolder(paramTypes.length);
		Set<ConstructorArgumentValues.ValueHolder> usedValueHolders = new HashSet<>(paramTypes.length);
		Set<String> autowiredBeanNames = new LinkedHashSet<>(4);
		for (int paramIndex = 0; paramIndex < paramTypes.length; paramIndex++) {
			Class<?> paramType = paramTypes[paramIndex];
			String paramName = (paramNames != null ? paramNames[paramIndex] : "");
			ConstructorArgumentValues.ValueHolder valueHolder = null;
			if (resolvedValues != null) {
				valueHolder = resolvedValues.getArgumentValue(paramIndex, paramType, paramName, usedValueHolders);
				if (valueHolder == null && (!autowiring || paramTypes.length == resolvedValues.getArgumentCount())) {
					valueHolder = resolvedValues.getGenericArgumentValue(null, null, usedValueHolders);
				}
			}
			if (valueHolder != null) {
				usedValueHolders.add(valueHolder);
				Object originalValue = valueHolder.getValue();
				Object convertedValue;
				if (valueHolder.isConverted()) {
					convertedValue = valueHolder.getConvertedValue();
					args.preparedArguments[paramIndex] = convertedValue;
				} else {
					MethodParameter methodParam = MethodParameter.forExecutable(executable, paramIndex);
					try {
						convertedValue = converter.convertIfNecessary(originalValue, paramType, methodParam);
					} catch (TypeMismatchException ex) {
						throw new UnsatisfiedDependencyException(
								mbd.getResourceDescription(), beanName, new InjectionPoint(methodParam),
								"Could not convert argument value of type [" +
										ObjectUtils.nullSafeClassName(valueHolder.getValue()) +
										"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
					}
					Object sourceHolder = valueHolder.getSource();
					if (sourceHolder instanceof ConstructorArgumentValues.ValueHolder) {
						Object sourceValue = ((ConstructorArgumentValues.ValueHolder) sourceHolder).getValue();
						args.resolveNecessary = true;
						args.preparedArguments[paramIndex] = sourceValue;
					}
				}
				args.arguments[paramIndex] = convertedValue;
				args.rawArguments[paramIndex] = originalValue;
			} else {
				MethodParameter methodParam = MethodParameter.forExecutable(executable, paramIndex);
				if (!autowiring) {
					throw new UnsatisfiedDependencyException(
							mbd.getResourceDescription(), beanName, new InjectionPoint(methodParam),
							"Ambiguous argument values for parameter of type [" + paramType.getName() +
									"] - did you specify the correct bean references as arguments?");
				}
				try {
					Object autowiredArgument = resolveAutowiredArgument(
							methodParam, beanName, autowiredBeanNames, converter, fallback);
					args.rawArguments[paramIndex] = autowiredArgument;
					args.arguments[paramIndex] = autowiredArgument;
					args.preparedArguments[paramIndex] = autowiredArgumentMarker;
					args.resolveNecessary = true;
				} catch (BeansException ex) {
					throw new UnsatisfiedDependencyException(
							mbd.getResourceDescription(), beanName, new InjectionPoint(methodParam), ex);
				}
			}
		}
		for (String autowiredBeanName : autowiredBeanNames) {
			this.beanFactory.registerDependentBean(autowiredBeanName, beanName);
			if (logger.isDebugEnabled()) {
				logger.debug("Autowiring by type from bean name '" + beanName +
						"' via " + (executable instanceof Constructor ? "constructor" : "factory method") +
						" to bean named '" + autowiredBeanName + "'");
			}
		}
		return args;
	}
private ArgumentsHolder createArgumentArray ( String beanName , RootBeanDefinition mbd , @ Nullable ConstructorArgumentValues resolvedValues , BeanWrapper bw , Class < ? > [ ] paramTypes , @ Nullable String [ ] paramNames , Executable executable , boolean autowiring , boolean fallback ) throws UnsatisfiedDependencyException { TypeConverter customConverter = this . beanFactory . getCustomTypeConverter ( ) ; TypeConverter converter = ( customConverter != null ? customConverter : bw ) ; ArgumentsHolder args = new ArgumentsHolder ( paramTypes . length ) ; Set < ConstructorArgumentValues . ValueHolder > usedValueHolders = new HashSet < > ( paramTypes . length ) ; Set < String > autowiredBeanNames = new LinkedHashSet < > ( 4 ) ; for ( int paramIndex = 0 ; paramIndex < paramTypes . length ; paramIndex ++ ) { Class < ? > paramType = paramTypes [ paramIndex ] ; String paramName = ( paramNames != null ? paramNames [ paramIndex ] : "" ) ; ConstructorArgumentValues . ValueHolder valueHolder = null ; if ( resolvedValues != null ) { valueHolder = resolvedValues . getArgumentValue ( paramIndex , paramType , paramName , usedValueHolders ) ; if ( valueHolder == null && ( ! autowiring || paramTypes . length == resolvedValues . getArgumentCount ( ) ) ) { valueHolder = resolvedValues . getGenericArgumentValue ( null , null , usedValueHolders ) ; } } if ( valueHolder != null ) { usedValueHolders . add ( valueHolder ) ; Object originalValue = valueHolder . getValue ( ) ; Object convertedValue ; if ( valueHolder . isConverted ( ) ) { convertedValue = valueHolder . getConvertedValue ( ) ; args . preparedArguments [ paramIndex ] = convertedValue ; } else { MethodParameter methodParam = MethodParameter . forExecutable ( executable , paramIndex ) ; try { convertedValue = converter . convertIfNecessary ( originalValue , paramType , methodParam ) ; } catch ( TypeMismatchException ex ) { throw new UnsatisfiedDependencyException ( mbd . getResourceDescription ( ) , beanName , new InjectionPoint ( methodParam ) , "Could not convert argument value of type [" + ObjectUtils . nullSafeClassName ( valueHolder . getValue ( ) ) + "] to required type [" + paramType . getName ( ) + "]: " + ex . getMessage ( ) ) ; } Object sourceHolder = valueHolder . getSource ( ) ; if ( sourceHolder instanceof ConstructorArgumentValues . ValueHolder ) { Object sourceValue = ( ( ConstructorArgumentValues . ValueHolder ) sourceHolder ) . getValue ( ) ; args . resolveNecessary = true ; args . preparedArguments [ paramIndex ] = sourceValue ; } } args . arguments [ paramIndex ] = convertedValue ; args . rawArguments [ paramIndex ] = originalValue ; } else { MethodParameter methodParam = MethodParameter . forExecutable ( executable , paramIndex ) ; if ( ! autowiring ) { throw new UnsatisfiedDependencyException ( mbd . getResourceDescription ( ) , beanName , new InjectionPoint ( methodParam ) , "Ambiguous argument values for parameter of type [" + paramType . getName ( ) + "] - did you specify the correct bean references as arguments?" ) ; } try { Object autowiredArgument = resolveAutowiredArgument ( methodParam , beanName , autowiredBeanNames , converter , fallback ) ; args . rawArguments [ paramIndex ] = autowiredArgument ; args . arguments [ paramIndex ] = autowiredArgument ; args . preparedArguments [ paramIndex ] = autowiredArgumentMarker ; args . resolveNecessary = true ; } catch ( BeansException ex ) { throw new UnsatisfiedDependencyException ( mbd . getResourceDescription ( ) , beanName , new InjectionPoint ( methodParam ) , ex ) ; } } } for ( String autowiredBeanName : autowiredBeanNames ) { this . beanFactory . registerDependentBean ( autowiredBeanName , beanName ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Autowiring by type from bean name '" + beanName + "' via " + ( executable instanceof Constructor ? "constructor" : "factory method" ) + " to bean named '" + autowiredBeanName + "'" ) ; } } return args ; }
Create an array of arguments to invoke a constructor or factory method,
 given the resolved constructor argument values.
Create an array of arguments to invoke a constructor or factory method given the resolved constructor argument values .
// Try to find matching constructor argument value, either indexed or generic. // If we couldn't find a direct match and are not supposed to autowire, // let's try the next generic, untyped argument value as fallback: // it could match after type conversion (for example, String -> int). // We found a potential match - let's give it a try. // Do not consider the same value definition multiple times! // No explicit match found: we're either supposed to autowire or // have to fail creating an argument array for the given constructor.