Example usage for org.springframework.aop.framework.autoproxy AutoProxyUtils determineTargetClass

List of usage examples for org.springframework.aop.framework.autoproxy AutoProxyUtils determineTargetClass

Introduction

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

Prototype

@Nullable
public static Class<?> determineTargetClass(ConfigurableListableBeanFactory beanFactory,
        @Nullable String beanName) 

Source Link

Document

Determine the original target class for the specified bean, if possible, otherwise falling back to a regular getType lookup.

Usage

From source file:org.springframework.cloud.task.listener.annotation.TaskListenerExecutorFactoryBean.java

private void initializeExecutor() {
    ConfigurableListableBeanFactory factory = context.getBeanFactory();
    for (String beanName : context.getBeanDefinitionNames()) {

        if (!ScopedProxyUtils.isScopedTarget(beanName)) {
            Class<?> type = null;
            try {
                type = AutoProxyUtils.determineTargetClass(factory, beanName);
            } catch (RuntimeException ex) {
                // An unresolvable bean type, probably from a lazy bean - let's ignore it.
                if (logger.isDebugEnabled()) {
                    logger.debug("Could not resolve target class for bean with name '" + beanName + "'", ex);
                }/*www  .ja  v  a2 s  .  co  m*/
            }
            if (type != null) {
                if (ScopedObject.class.isAssignableFrom(type)) {
                    try {
                        type = AutoProxyUtils.determineTargetClass(factory,
                                ScopedProxyUtils.getTargetBeanName(beanName));
                    } catch (RuntimeException ex) {
                        // An invalid scoped proxy arrangement - let's ignore it.
                        if (logger.isDebugEnabled()) {
                            logger.debug("Could not resolve target bean for scoped proxy '" + beanName + "'",
                                    ex);
                        }
                    }
                }
                try {
                    processBean(beanName, type);
                } catch (RuntimeException ex) {
                    throw new BeanInitializationException("Failed to process @BeforeTask "
                            + "annotation on bean with name '" + beanName + "'", ex);
                }
            }
        }
    }

}

From source file:org.springframework.context.event.EventListenerMethodProcessor.java

@Override
public void afterSingletonsInstantiated() {
    List<EventListenerFactory> factories = getEventListenerFactories();
    ConfigurableApplicationContext context = getApplicationContext();
    String[] beanNames = context.getBeanNamesForType(Object.class);
    for (String beanName : beanNames) {
        if (!ScopedProxyUtils.isScopedTarget(beanName)) {
            Class<?> type = null;
            try {
                type = AutoProxyUtils.determineTargetClass(context.getBeanFactory(), beanName);
            } catch (Throwable ex) {
                // An unresolvable bean type, probably from a lazy bean - let's ignore it.
                if (logger.isDebugEnabled()) {
                    logger.debug("Could not resolve target class for bean with name '" + beanName + "'", ex);
                }/*from  w  ww . j a v a  2 s  . c o  m*/
            }
            if (type != null) {
                if (ScopedObject.class.isAssignableFrom(type)) {
                    try {
                        Class<?> targetClass = AutoProxyUtils.determineTargetClass(context.getBeanFactory(),
                                ScopedProxyUtils.getTargetBeanName(beanName));
                        if (targetClass != null) {
                            type = targetClass;
                        }
                    } catch (Throwable ex) {
                        // An invalid scoped proxy arrangement - let's ignore it.
                        if (logger.isDebugEnabled()) {
                            logger.debug("Could not resolve target bean for scoped proxy '" + beanName + "'",
                                    ex);
                        }
                    }
                }
                try {
                    processBean(factories, beanName, type);
                } catch (Throwable ex) {
                    throw new BeanInitializationException("Failed to process @EventListener "
                            + "annotation on bean with name '" + beanName + "'", ex);
                }
            }
        }
    }
}