Java Code Examples for org.springframework.beans.factory.config.ConfigurableListableBeanFactory#getMergedBeanDefinition()

The following examples show how to use org.springframework.beans.factory.config.ConfigurableListableBeanFactory#getMergedBeanDefinition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoProxyUtils.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Determine the original target class for the specified bean, if possible,
 * otherwise falling back to a regular {@code getType} lookup.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @return the original target class as stored in the bean definition, if any
 * @since 4.2.3
 * @see org.springframework.beans.factory.BeanFactory#getType(String)
 */
@Nullable
public static Class<?> determineTargetClass(
		ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) {

	if (beanName == null) {
		return null;
	}
	if (beanFactory.containsBeanDefinition(beanName)) {
		BeanDefinition bd = beanFactory.getMergedBeanDefinition(beanName);
		Class<?> targetClass = (Class<?>) bd.getAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE);
		if (targetClass != null) {
			return targetClass;
		}
	}
	return beanFactory.getType(beanName);
}
 
Example 2
Source File: AutoProxyUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Determine the original target class for the specified bean, if possible,
 * otherwise falling back to a regular {@code getType} lookup.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @return the original target class as stored in the bean definition, if any
 * @since 4.2.3
 * @see org.springframework.beans.factory.BeanFactory#getType(String)
 */
@Nullable
public static Class<?> determineTargetClass(
		ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) {

	if (beanName == null) {
		return null;
	}
	if (beanFactory.containsBeanDefinition(beanName)) {
		BeanDefinition bd = beanFactory.getMergedBeanDefinition(beanName);
		Class<?> targetClass = (Class<?>) bd.getAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE);
		if (targetClass != null) {
			return targetClass;
		}
	}
	return beanFactory.getType(beanName);
}
 
Example 3
Source File: GenericTypeAwareAutowireCandidateResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Nullable
protected RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition rbd) {
	BeanDefinitionHolder decDef = rbd.getDecoratedDefinition();
	if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory) {
		ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) this.beanFactory;
		if (clbf.containsBeanDefinition(decDef.getBeanName())) {
			BeanDefinition dbd = clbf.getMergedBeanDefinition(decDef.getBeanName());
			if (dbd instanceof RootBeanDefinition) {
				return (RootBeanDefinition) dbd;
			}
		}
	}
	return null;
}
 
Example 4
Source File: GenericTypeAwareAutowireCandidateResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Nullable
protected RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition rbd) {
	BeanDefinitionHolder decDef = rbd.getDecoratedDefinition();
	if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory) {
		ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) this.beanFactory;
		if (clbf.containsBeanDefinition(decDef.getBeanName())) {
			BeanDefinition dbd = clbf.getMergedBeanDefinition(decDef.getBeanName());
			if (dbd instanceof RootBeanDefinition) {
				return (RootBeanDefinition) dbd;
			}
		}
	}
	return null;
}
 
Example 5
Source File: GenericTypeAwareAutowireCandidateResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition rbd) {
	BeanDefinitionHolder decDef = rbd.getDecoratedDefinition();
	if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory) {
		ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) this.beanFactory;
		if (clbf.containsBeanDefinition(decDef.getBeanName())) {
			BeanDefinition dbd = clbf.getMergedBeanDefinition(decDef.getBeanName());
			if (dbd instanceof RootBeanDefinition) {
				return (RootBeanDefinition) dbd;
			}
		}
	}
	return null;
}
 
Example 6
Source File: AutoProxyUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determine the original target class for the specified bean, if possible,
 * otherwise falling back to a regular {@code getType} lookup.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @return the original target class as stored in the bean definition, if any
 * @since 4.2.3
 * @see org.springframework.beans.factory.BeanFactory#getType(String)
 */
public static Class<?> determineTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName) {
	if (beanName == null) {
		return null;
	}
	if (beanFactory.containsBeanDefinition(beanName)) {
		BeanDefinition bd = beanFactory.getMergedBeanDefinition(beanName);
		Class<?> targetClass = (Class<?>) bd.getAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE);
		if (targetClass != null) {
			return targetClass;
		}
	}
	return beanFactory.getType(beanName);
}
 
Example 7
Source File: BeanFactoryAnnotationUtils.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the named bean declares a qualifier of the given name.
 * @param qualifier the qualifier to match
 * @param beanName the name of the candidate bean
 * @param bf the {@code BeanFactory} from which to retrieve the named bean
 * @return {@code true} if either the bean definition (in the XML case)
 * or the bean's factory method (in the {@code @Bean} case) defines a matching
 * qualifier value (through {@code <qualifier>} or {@code @Qualifier})
 */
private static boolean isQualifierMatch(String qualifier, String beanName, ConfigurableListableBeanFactory bf) {
	if (bf.containsBean(beanName)) {
		try {
			BeanDefinition bd = bf.getMergedBeanDefinition(beanName);
			if (bd instanceof AbstractBeanDefinition) {
				AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
				AutowireCandidateQualifier candidate = abd.getQualifier(Qualifier.class.getName());
				if ((candidate != null && qualifier.equals(candidate.getAttribute(AutowireCandidateQualifier.VALUE_KEY))) ||
						qualifier.equals(beanName) || ObjectUtils.containsElement(bf.getAliases(beanName), qualifier)) {
					return true;
				}
			}
			if (bd instanceof RootBeanDefinition) {
				Method factoryMethod = ((RootBeanDefinition) bd).getResolvedFactoryMethod();
				if (factoryMethod != null) {
					Qualifier targetAnnotation = factoryMethod.getAnnotation(Qualifier.class);
					if (targetAnnotation != null && qualifier.equals(targetAnnotation.value())) {
						return true;
					}
				}
			}
		}
		catch (NoSuchBeanDefinitionException ex) {
			// ignore - can't compare qualifiers for a manually registered singleton object
		}
	}
	return false;
}
 
Example 8
Source File: GenericTypeAwareAutowireCandidateResolver.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
protected RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition rbd) {
	BeanDefinitionHolder decDef = rbd.getDecoratedDefinition();
	if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory) {
		ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) this.beanFactory;
		if (clbf.containsBeanDefinition(decDef.getBeanName())) {
			BeanDefinition dbd = clbf.getMergedBeanDefinition(decDef.getBeanName());
			if (dbd instanceof RootBeanDefinition) {
				return (RootBeanDefinition) dbd;
			}
		}
	}
	return null;
}
 
Example 9
Source File: AutoProxyUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Determine the original target class for the specified bean, if possible,
 * otherwise falling back to a regular {@code getType} lookup.
 * @param beanFactory the containing ConfigurableListableBeanFactory
 * @param beanName the name of the bean
 * @return the original target class as stored in the bean definition, if any
 * @since 4.2.3
 * @see org.springframework.beans.factory.BeanFactory#getType(String)
 */
public static Class<?> determineTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName) {
	if (beanName == null) {
		return null;
	}
	if (beanFactory.containsBeanDefinition(beanName)) {
		BeanDefinition bd = beanFactory.getMergedBeanDefinition(beanName);
		Class<?> targetClass = (Class<?>) bd.getAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE);
		if (targetClass != null) {
			return targetClass;
		}
	}
	return beanFactory.getType(beanName);
}
 
Example 10
Source File: BeanFactoryAnnotationUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the named bean declares a qualifier of the given name.
 * @param qualifier the qualifier to match
 * @param beanName the name of the candidate bean
 * @param bf the {@code BeanFactory} from which to retrieve the named bean
 * @return {@code true} if either the bean definition (in the XML case)
 * or the bean's factory method (in the {@code @Bean} case) defines a matching
 * qualifier value (through {@code <qualifier>} or {@code @Qualifier})
 */
private static boolean isQualifierMatch(String qualifier, String beanName, ConfigurableListableBeanFactory bf) {
	if (bf.containsBean(beanName)) {
		try {
			BeanDefinition bd = bf.getMergedBeanDefinition(beanName);
			if (bd instanceof AbstractBeanDefinition) {
				AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
				AutowireCandidateQualifier candidate = abd.getQualifier(Qualifier.class.getName());
				if ((candidate != null && qualifier.equals(candidate.getAttribute(AutowireCandidateQualifier.VALUE_KEY))) ||
						qualifier.equals(beanName) || ObjectUtils.containsElement(bf.getAliases(beanName), qualifier)) {
					return true;
				}
			}
			if (bd instanceof RootBeanDefinition) {
				Method factoryMethod = ((RootBeanDefinition) bd).getResolvedFactoryMethod();
				if (factoryMethod != null) {
					Qualifier targetAnnotation = factoryMethod.getAnnotation(Qualifier.class);
					if (targetAnnotation != null && qualifier.equals(targetAnnotation.value())) {
						return true;
					}
				}
			}
		}
		catch (NoSuchBeanDefinitionException ex) {
			// Ignore - can't compare qualifiers for a manually registered singleton object
		}
	}
	return false;
}
 
Example 11
Source File: GenericTypeAwareAutowireCandidateResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition rbd) {
	BeanDefinitionHolder decDef = rbd.getDecoratedDefinition();
	if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory) {
		ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) this.beanFactory;
		if (clbf.containsBeanDefinition(decDef.getBeanName())) {
			BeanDefinition dbd = clbf.getMergedBeanDefinition(decDef.getBeanName());
			if (dbd instanceof RootBeanDefinition) {
				return (RootBeanDefinition) dbd;
			}
		}
	}
	return null;
}