|
|
|
@ -589,14 +589,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) { |
|
|
|
protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) { |
|
|
|
Class<?> targetType = mbd.getTargetType(); |
|
|
|
Class<?> targetType = determineTargetType(beanName, mbd, typesToMatch); |
|
|
|
if (targetType == null) { |
|
|
|
|
|
|
|
targetType = (mbd.getFactoryMethodName() != null ? getTypeForFactoryMethod(beanName, mbd, typesToMatch) : |
|
|
|
|
|
|
|
resolveBeanClass(mbd, beanName, typesToMatch)); |
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(typesToMatch) || getTempClassLoader() == null) { |
|
|
|
|
|
|
|
mbd.setTargetType(targetType); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Apply SmartInstantiationAwareBeanPostProcessors to predict the
|
|
|
|
// Apply SmartInstantiationAwareBeanPostProcessors to predict the
|
|
|
|
// eventual type after a before-instantiation shortcut.
|
|
|
|
// eventual type after a before-instantiation shortcut.
|
|
|
|
if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) { |
|
|
|
if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) { |
|
|
|
@ -615,7 +609,27 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Determine the bean type for the given bean definition which is based on |
|
|
|
* Determine the target type for the given bean definition. |
|
|
|
|
|
|
|
* @param beanName the name of the bean (for error handling purposes) |
|
|
|
|
|
|
|
* @param mbd the merged bean definition for the bean |
|
|
|
|
|
|
|
* @param typesToMatch the types to match in case of internal type matching purposes |
|
|
|
|
|
|
|
* (also signals that the returned {@code Class} will never be exposed to application code) |
|
|
|
|
|
|
|
* @return the type for the bean if determinable, or {@code null} otherwise |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected Class<?> determineTargetType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) { |
|
|
|
|
|
|
|
Class<?> targetType = mbd.getTargetType(); |
|
|
|
|
|
|
|
if (targetType == null) { |
|
|
|
|
|
|
|
targetType = (mbd.getFactoryMethodName() != null ? getTypeForFactoryMethod(beanName, mbd, typesToMatch) : |
|
|
|
|
|
|
|
resolveBeanClass(mbd, beanName, typesToMatch)); |
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(typesToMatch) || getTempClassLoader() == null) { |
|
|
|
|
|
|
|
mbd.setTargetType(targetType); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return targetType; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Determine the target type for the given bean definition which is based on |
|
|
|
* a factory method. Only called if there is no singleton instance registered |
|
|
|
* a factory method. Only called if there is no singleton instance registered |
|
|
|
* for the target bean already. |
|
|
|
* for the target bean already. |
|
|
|
* <p>This implementation determines the type matching {@link #createBean}'s |
|
|
|
* <p>This implementation determines the type matching {@link #createBean}'s |
|
|
|
@ -625,7 +639,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac |
|
|
|
* @param mbd the merged bean definition for the bean |
|
|
|
* @param mbd the merged bean definition for the bean |
|
|
|
* @param typesToMatch the types to match in case of internal type matching purposes |
|
|
|
* @param typesToMatch the types to match in case of internal type matching purposes |
|
|
|
* (also signals that the returned {@code Class} will never be exposed to application code) |
|
|
|
* (also signals that the returned {@code Class} will never be exposed to application code) |
|
|
|
* @return the type for the bean if determinable, or {@code null} else |
|
|
|
* @return the type for the bean if determinable, or {@code null} otherwise |
|
|
|
* @see #createBean |
|
|
|
* @see #createBean |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) { |
|
|
|
protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) { |
|
|
|
@ -927,10 +941,13 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac |
|
|
|
Object bean = null; |
|
|
|
Object bean = null; |
|
|
|
if (!Boolean.FALSE.equals(mbd.beforeInstantiationResolved)) { |
|
|
|
if (!Boolean.FALSE.equals(mbd.beforeInstantiationResolved)) { |
|
|
|
// Make sure bean class is actually resolved at this point.
|
|
|
|
// Make sure bean class is actually resolved at this point.
|
|
|
|
if (mbd.hasBeanClass() && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) { |
|
|
|
if (!mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) { |
|
|
|
bean = applyBeanPostProcessorsBeforeInstantiation(mbd.getBeanClass(), beanName); |
|
|
|
Class<?> targetType = determineTargetType(beanName, mbd); |
|
|
|
if (bean != null) { |
|
|
|
if (targetType != null) { |
|
|
|
bean = applyBeanPostProcessorsAfterInitialization(bean, beanName); |
|
|
|
bean = applyBeanPostProcessorsBeforeInstantiation(targetType, beanName); |
|
|
|
|
|
|
|
if (bean != null) { |
|
|
|
|
|
|
|
bean = applyBeanPostProcessorsAfterInitialization(bean, beanName); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
mbd.beforeInstantiationResolved = (bean != null); |
|
|
|
mbd.beforeInstantiationResolved = (bean != null); |
|
|
|
|