Example usage for org.springframework.beans.factory.config SmartInstantiationAwareBeanPostProcessor predictBeanType

List of usage examples for org.springframework.beans.factory.config SmartInstantiationAwareBeanPostProcessor predictBeanType

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config SmartInstantiationAwareBeanPostProcessor predictBeanType.

Prototype

@Nullable
default Class<?> predictBeanType(Class<?> beanClass, String beanName) throws BeansException 

Source Link

Document

Predict the type of the bean to be eventually returned from this processor's #postProcessBeforeInstantiation callback.

Usage

From source file:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.java

@Override
@Nullable//from  www.  j  ava2s  .  co m
protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) {
    Class<?> targetType = determineTargetType(beanName, mbd, typesToMatch);

    // Apply SmartInstantiationAwareBeanPostProcessors to predict the
    // eventual type after a before-instantiation shortcut.
    if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
        for (BeanPostProcessor bp : getBeanPostProcessors()) {
            if (bp instanceof SmartInstantiationAwareBeanPostProcessor) {
                SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp;
                Class<?> predicted = ibp.predictBeanType(targetType, beanName);
                if (predicted != null && (typesToMatch.length != 1 || FactoryBean.class != typesToMatch[0]
                        || FactoryBean.class.isAssignableFrom(predicted))) {
                    return predicted;
                }
            }
        }
    }
    return targetType;
}