List of usage examples for org.springframework.aop.scope ScopedProxyUtils isScopedTarget
public static boolean isScopedTarget(@Nullable String beanName)
From source file:org.springframework.boot.web.servlet.ServletContextInitializerBeans.java
private <T> List<Entry<String, T>> getOrderedBeansOfType(ListableBeanFactory beanFactory, Class<T> type, Set<?> excludes) {/*from www . ja v a 2 s .c o m*/ List<Entry<String, T>> beans = new ArrayList<Entry<String, T>>(); Comparator<Entry<String, T>> comparator = new Comparator<Entry<String, T>>() { @Override public int compare(Entry<String, T> o1, Entry<String, T> o2) { return AnnotationAwareOrderComparator.INSTANCE.compare(o1.getValue(), o2.getValue()); } }; String[] names = beanFactory.getBeanNamesForType(type, true, false); Map<String, T> map = new LinkedHashMap<String, T>(); for (String name : names) { if (!excludes.contains(name) && !ScopedProxyUtils.isScopedTarget(name)) { T bean = beanFactory.getBean(name, type); if (!excludes.contains(bean)) { map.put(name, bean); } } } beans.addAll(map.entrySet()); Collections.sort(beans, comparator); return beans; }
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); }//from w w w .j a va 2 s. c o 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); }/* w w w .j a v a 2 s . c om*/ } 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); } } } } }