Example usage for org.springframework.aop.framework.autoproxy TargetSourceCreator getTargetSource

List of usage examples for org.springframework.aop.framework.autoproxy TargetSourceCreator getTargetSource

Introduction

In this page you can find the example usage for org.springframework.aop.framework.autoproxy TargetSourceCreator getTargetSource.

Prototype

@Nullable
TargetSource getTargetSource(Class<?> beanClass, String beanName);

Source Link

Document

Create a special TargetSource for the given bean, if any.

Usage

From source file:org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.java

/**
 * Create a target source for bean instances. Uses any TargetSourceCreators if set.
 * Returns {@code null} if no custom TargetSource should be used.
 * <p>This implementation uses the "customTargetSourceCreators" property.
 * Subclasses can override this method to use a different mechanism.
 * @param beanClass the class of the bean to create a TargetSource for
 * @param beanName the name of the bean//  w  w  w  . j a  v  a2s  .  c o m
 * @return a TargetSource for this bean
 * @see #setCustomTargetSourceCreators
 */
@Nullable
protected TargetSource getCustomTargetSource(Class<?> beanClass, String beanName) {
    // We can't create fancy target sources for directly registered singletons.
    if (this.customTargetSourceCreators != null && this.beanFactory != null
            && this.beanFactory.containsBean(beanName)) {
        for (TargetSourceCreator tsc : this.customTargetSourceCreators) {
            TargetSource ts = tsc.getTargetSource(beanClass, beanName);
            if (ts != null) {
                // Found a matching TargetSource.
                if (logger.isDebugEnabled()) {
                    logger.debug("TargetSourceCreator [" + tsc
                            + " found custom TargetSource for bean with name '" + beanName + "'");
                }
                return ts;
            }
        }
    }

    // No custom TargetSource found.
    return null;
}