|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.beans.factory.support.ConstructorResolver
abstract class ConstructorResolver
Helper class for resolving constructors and factory methods. Performs constructor resolution through argument matching.
Works on an AbstractBeanFactory and an InstantiationStrategy. Used by AbstractAutowireCapableBeanFactory.
autowireConstructor(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition)
,
instantiateUsingFactoryMethod(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[])
,
AbstractAutowireCapableBeanFactory
Field Summary | |
---|---|
protected Log |
logger
Logger available to subclasses |
Constructor Summary | |
---|---|
ConstructorResolver(AbstractBeanFactory beanFactory,
InstantiationStrategy instantiationStrategy)
Create a new ConstructorResolver for the given factory and instantiation strategy. |
Method Summary | |
---|---|
protected BeanWrapper |
autowireConstructor(String beanName,
RootBeanDefinition mergedBeanDefinition)
"autowire constructor" (with constructor arguments by type) behavior. |
protected abstract Map |
findAutowireCandidates(String beanName,
Class requiredType)
Find bean instances that match the required type. |
BeanWrapper |
instantiateUsingFactoryMethod(String beanName,
RootBeanDefinition mergedBeanDefinition,
Object[] explicitArgs)
Instantiate the bean using a named factory method. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Log logger
Constructor Detail |
---|
public ConstructorResolver(AbstractBeanFactory beanFactory, InstantiationStrategy instantiationStrategy)
beanFactory
- the BeanFactory to work withinstantiationStrategy
- the instantiate strategy for creating bean instancesMethod Detail |
---|
protected BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mergedBeanDefinition) throws BeansException
This corresponds to constructor injection: In this mode, a Spring bean factory is able to host components that expect constructor-based dependency resolution.
beanName
- name of the beanmergedBeanDefinition
- the bean definition for the bean
BeansException
public BeanWrapper instantiateUsingFactoryMethod(String beanName, RootBeanDefinition mergedBeanDefinition, Object[] explicitArgs) throws BeansException
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
- name of the beanmergedBeanDefinition
- the 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)
BeansException
protected abstract Map findAutowireCandidates(String beanName, Class requiredType) throws BeansException
If a subclass cannot obtain information about bean names by type, a corresponding exception should be thrown.
beanName
- the name of the bean that is about to be wiredrequiredType
- the type of the autowired constructor argument
null
)
BeansException
- in case of errorsautowireConstructor(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition)
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |