Example usage for org.springframework.beans.factory.wiring BeanWiringInfo getAutowireMode

List of usage examples for org.springframework.beans.factory.wiring BeanWiringInfo getAutowireMode

Introduction

In this page you can find the example usage for org.springframework.beans.factory.wiring BeanWiringInfo getAutowireMode.

Prototype

public int getAutowireMode() 

Source Link

Document

Return one of the constants #AUTOWIRE_BY_NAME / #AUTOWIRE_BY_TYPE , if autowiring is indicated.

Usage

From source file:org.springframework.beans.factory.wiring.BeanConfigurerSupport.java

/**
 * Configure the bean instance.//  w ww  .j a  v a 2s  . com
 * <p>Subclasses can override this to provide custom configuration logic.
 * Typically called by an aspect, for all bean instances matched by a pointcut.
 * @param beanInstance the bean instance to configure (must <b>not</b> be {@code null})
 */
public void configureBean(Object beanInstance) {
    if (this.beanFactory == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("BeanFactory has not been set on " + ClassUtils.getShortName(getClass()) + ": "
                    + "Make sure this configurer runs in a Spring container. Unable to configure bean of type ["
                    + ClassUtils.getDescriptiveType(beanInstance) + "]. Proceeding without injection.");
        }
        return;
    }

    BeanWiringInfoResolver bwiResolver = this.beanWiringInfoResolver;
    Assert.state(bwiResolver != null, "No BeanWiringInfoResolver available");
    BeanWiringInfo bwi = bwiResolver.resolveWiringInfo(beanInstance);
    if (bwi == null) {
        // Skip the bean if no wiring info given.
        return;
    }

    ConfigurableListableBeanFactory beanFactory = this.beanFactory;
    Assert.state(beanFactory != null, "No BeanFactory available");
    try {
        if (bwi.indicatesAutowiring() || (bwi.isDefaultBeanName() && bwi.getBeanName() != null
                && !beanFactory.containsBean(bwi.getBeanName()))) {
            // Perform autowiring (also applying standard factory / post-processor callbacks).
            beanFactory.autowireBeanProperties(beanInstance, bwi.getAutowireMode(), bwi.getDependencyCheck());
            beanFactory.initializeBean(beanInstance, bwi.getBeanName());
        } else {
            // Perform explicit wiring based on the specified bean definition.
            beanFactory.configureBean(beanInstance, bwi.getBeanName());
        }
    } catch (BeanCreationException ex) {
        Throwable rootCause = ex.getMostSpecificCause();
        if (rootCause instanceof BeanCurrentlyInCreationException) {
            BeanCreationException bce = (BeanCreationException) rootCause;
            String bceBeanName = bce.getBeanName();
            if (bceBeanName != null && beanFactory.isCurrentlyInCreation(bceBeanName)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Failed to create target bean '" + bce.getBeanName()
                            + "' while configuring object of type [" + beanInstance.getClass().getName()
                            + "] - probably due to a circular reference. This is a common startup situation "
                            + "and usually not fatal. Proceeding without injection. Original exception: " + ex);
                }
                return;
            }
        }
        throw ex;
    }
}