Spring源码分析-IOC之AutowireCapableBeanFactory

AutowireCapableBeanFactory继承自BeanFactory,具有BeanFactory的功能以外,提供创建bean,自动注入,初始化以及应用bean的后置处理,我们来分析下具体的源码:
 

public interface AutowireCapableBeanFactory extends BeanFactory {

	/**
	 * Constant that indicates no externally defined autowiring. Note that
	 * BeanFactoryAware etc and annotation-driven injection will still be applied.
	 * @see #createBean
	 * @see #autowire
	 * @see #autowireBeanProperties
	 */
    //表明没有自动装配的bean
	int AUTOWIRE_NO = 0;

	//根据名称自动装配bean
	int AUTOWIRE_BY_NAME = 1;

	//根据类型自动装配bean
	int AUTOWIRE_BY_TYPE = 2;

	//根据构造器自动装配bean
	int AUTOWIRE_CONSTRUCTOR = 3;

	//通过class的内部来自动装配bean
    //已经被启用
	@Deprecated
	int AUTOWIRE_AUTODETECT = 4;


	//-------------------------------------------------------------------------
	// Typical methods for creating and populating external bean instances
	//-------------------------------------------------------------------------

	//根据给定的class创建bean
	<T> T createBean(Class<T> beanClass) throws BeansException;

	//通过调用给定Bean的after-instantiation及post-processing接口,对bean进行配置。
	void autowireBean(Object existingBean) throws BeansException;

	// 配置参数中指定的bean,包括自动装配其域,对其应用如setBeanName功能的回调函数。
	Object configureBean(Object existingBean, String beanName) throws BeansException;

	//解析出在Factory中与指定Bean有指定依赖关系的Bean
	Object resolveDependency(DependencyDescriptor descriptor, String beanName) throws BeansException;


	// 创建一个指定class的实例,通过参数可以指定其自动装配模式(by-name or by-type).
	Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;

	//通过指定的自动装配策略来初始化一个Bean。
	Object autowire(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;

	// 通过指定的自动装配方式来对给定的Bean进行自动装配
	void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck)
			throws BeansException;

	//将参数中指定了那么的Bean,注入给定实例当中
	void applyBeanPropertyValues(Object existingBean, String beanName) throws BeansException;

	//初始化参数中指定的Bean,调用任何其注册的回调函数如setBeanName、setBeanFactory等。
	Object initializeBean(Object existingBean, String beanName) throws BeansException;

	//调用参数中指定Bean的postProcessBeforeInitialization方法
	Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
			throws BeansException;

	// 调用参数中指定Bean的postProcessAfterInitialization方法
	Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
			throws BeansException;

	//销毁参数中指定的Bean
	void destroyBean(Object existingBean);

	//解析指定Bean在Factory中的依赖关系
	Object resolveDependency(DependencyDescriptor descriptor, String beanName,
			Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException;

}

对于想要拥有自动装配能力,并且想要把这种能力暴露给外部应用BeanFactory类需要实现此接口。

猜你喜欢

转载自blog.csdn.net/cgsyck/article/details/88956939