class ConstructorResolver
extends java.lang.Object
autowireConstructor(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.reflect.Constructor<?>[], java.lang.Object[])
,
instantiateUsingFactoryMethod(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[])
,
AbstractAutowireCapableBeanFactory
Modifier and Type | Class and Description |
---|---|
private static class |
ConstructorResolver.ArgumentsHolder
Private inner class for holding argument combinations.
|
private static class |
ConstructorResolver.AutowiredArgumentMarker
Marker for autowired arguments in a cached argument array.
|
private static class |
ConstructorResolver.ConstructorPropertiesChecker
Delegate for checking Java 6's
ConstructorProperties annotation. |
Modifier and Type | Field and Description |
---|---|
private AbstractAutowireCapableBeanFactory |
beanFactory |
private static NamedThreadLocal<InjectionPoint> |
currentInjectionPoint |
Constructor and Description |
---|
ConstructorResolver(AbstractAutowireCapableBeanFactory beanFactory)
Create a new ConstructorResolver for the given factory and instantiation strategy.
|
Modifier and Type | Method and Description |
---|---|
BeanWrapper |
autowireConstructor(java.lang.String beanName,
RootBeanDefinition mbd,
java.lang.reflect.Constructor<?>[] chosenCtors,
java.lang.Object[] explicitArgs)
"autowire constructor" (with constructor arguments by type) behavior.
|
private ConstructorResolver.ArgumentsHolder |
createArgumentArray(java.lang.String beanName,
RootBeanDefinition mbd,
ConstructorArgumentValues resolvedValues,
BeanWrapper bw,
java.lang.Class<?>[] paramTypes,
java.lang.String[] paramNames,
java.lang.reflect.Executable executable,
boolean autowiring)
Create an array of arguments to invoke a constructor or factory method,
given the resolved constructor argument values.
|
private java.lang.reflect.Method[] |
getCandidateMethods(java.lang.Class<?> factoryClass,
RootBeanDefinition mbd)
Retrieve all candidate methods for the given class, considering
the
AbstractBeanDefinition.isNonPublicAccessAllowed() flag. |
protected java.lang.reflect.Constructor<?> |
getUserDeclaredConstructor(java.lang.reflect.Constructor<?> constructor) |
BeanWrapper |
instantiateUsingFactoryMethod(java.lang.String beanName,
RootBeanDefinition mbd,
java.lang.Object[] explicitArgs)
Instantiate the bean using a named factory method.
|
protected java.lang.Object |
resolveAutowiredArgument(MethodParameter param,
java.lang.String beanName,
java.util.Set<java.lang.String> autowiredBeanNames,
TypeConverter typeConverter)
Template method for resolving the specified argument which is supposed to be autowired.
|
private int |
resolveConstructorArguments(java.lang.String beanName,
RootBeanDefinition mbd,
BeanWrapper bw,
ConstructorArgumentValues cargs,
ConstructorArgumentValues resolvedValues)
Resolve the constructor arguments for this bean into the resolvedValues object.
|
void |
resolveFactoryMethodIfPossible(RootBeanDefinition mbd)
Resolve the factory method in the specified bean definition, if possible.
|
private java.lang.Object[] |
resolvePreparedArguments(java.lang.String beanName,
RootBeanDefinition mbd,
BeanWrapper bw,
java.lang.reflect.Executable executable,
java.lang.Object[] argsToResolve)
Resolve the prepared arguments stored in the given bean definition.
|
(package private) static InjectionPoint |
setCurrentInjectionPoint(InjectionPoint injectionPoint) |
private static final NamedThreadLocal<InjectionPoint> currentInjectionPoint
private final AbstractAutowireCapableBeanFactory beanFactory
public ConstructorResolver(AbstractAutowireCapableBeanFactory beanFactory)
beanFactory
- the BeanFactory to work withpublic BeanWrapper autowireConstructor(java.lang.String beanName, RootBeanDefinition mbd, java.lang.reflect.Constructor<?>[] chosenCtors, java.lang.Object[] explicitArgs)
This corresponds to constructor injection: In this mode, a Spring bean factory is able to host components that expect constructor-based dependency resolution.
beanName
- the name of the beanmbd
- the merged bean definition for the beanchosenCtors
- chosen candidate constructors (or null
if none)explicitArgs
- argument values passed in programmatically via the getBean method,
or null
if none (-> use constructor argument values from bean definition)public void resolveFactoryMethodIfPossible(RootBeanDefinition mbd)
RootBeanDefinition.getResolvedFactoryMethod()
can be checked for the result.mbd
- the bean definition to checkprivate java.lang.reflect.Method[] getCandidateMethods(java.lang.Class<?> factoryClass, RootBeanDefinition mbd)
AbstractBeanDefinition.isNonPublicAccessAllowed()
flag.
Called as the starting point for factory method determination.public BeanWrapper instantiateUsingFactoryMethod(java.lang.String beanName, RootBeanDefinition mbd, java.lang.Object[] explicitArgs)
Implementation requires iterating over the static or instance methods with the name specified in the RootBeanDefinition (the method may be overloaded) and trying to match with the parameters. We don't have the types attached to constructor args, so trial and error is the only way to go here. The explicitArgs array may contain argument values passed in programmatically via the corresponding getBean method.
beanName
- the name of the beanmbd
- the merged bean definition for the beanexplicitArgs
- argument values passed in programmatically via the getBean
method, or null
if none (-> use constructor argument values from bean definition)private int resolveConstructorArguments(java.lang.String beanName, RootBeanDefinition mbd, BeanWrapper bw, ConstructorArgumentValues cargs, ConstructorArgumentValues resolvedValues)
This method is also used for handling invocations of static factory methods.
private ConstructorResolver.ArgumentsHolder createArgumentArray(java.lang.String beanName, RootBeanDefinition mbd, ConstructorArgumentValues resolvedValues, BeanWrapper bw, java.lang.Class<?>[] paramTypes, java.lang.String[] paramNames, java.lang.reflect.Executable executable, boolean autowiring) throws UnsatisfiedDependencyException
UnsatisfiedDependencyException
private java.lang.Object[] resolvePreparedArguments(java.lang.String beanName, RootBeanDefinition mbd, BeanWrapper bw, java.lang.reflect.Executable executable, java.lang.Object[] argsToResolve)
protected java.lang.reflect.Constructor<?> getUserDeclaredConstructor(java.lang.reflect.Constructor<?> constructor)
protected java.lang.Object resolveAutowiredArgument(MethodParameter param, java.lang.String beanName, java.util.Set<java.lang.String> autowiredBeanNames, TypeConverter typeConverter)
static InjectionPoint setCurrentInjectionPoint(InjectionPoint injectionPoint)