/**
*1、对于想拥有自动装配能力,并且想要把这种能力暴露给外部应用的beanfactory需要实现该接口
*2、正常情况下,不要实现该接口,应该实现BeanFactory或者ListableBeanFactory接口
*3、需要注意的是ApplicationContext并没实现该接口。如果需要用到自动装配功能的话,可以调用ApplicationContext.getAutowireCapableBeanFactory()方法,来获取此接口实例。
*4、如果一个接口实现了该接口,很大程度上,还要实现BeanFactoryWare接口,这样子就能在上下文中返回BeanFactory
*/
public interface AutowireCapableBeanFactory extends BeanFactory {
//变量指明工厂没有自动装配的bean
int AUTOWIRE_NO = 0;
//根据名称自动装配
int AUTOWIRE_BY_NAME = 1;
//根据类型自动装配
int AUTOWIRE_BY_TYPE = 2;
//标识按照贪婪策略匹配出的最符合的构造方法来自动装配的常量
int AUTOWIRE_CONSTRUCTOR = 3;
//根据bean的class内部自动装配,但是Spring3.0后被弃用
@Deprecated
int AUTOWIRE_AUTODETECT = 4;
//参数:bean的class类型
//返回:bean的实例
//功能:根据bean的class类型,创建对应的bean实例
<T> T createBean(Class<T> beanClass) throws BeansException;
//使用autowireBeanProperties装配属性
void autowireBean(Object existingBean) throws BeansException;
//自动装配属性
Object configureBean(Object existingBean, String beanName) throws BeansException;
//-------------------------------------------------------------------------
// Specialized methods for fine-grained control over the bean lifecycle
//-------------------------------------------------------------------------
//对bean的生命周期进行细粒度控制的专门方法
//执行完整的bean初始化(包括:initializedBean和BeanPostProcessors)
//autowireMode:根据名字或类型来决定自动装配的方式
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的PostProcessorsAfterInitialization方法
Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
throws BeansException;
//销毁参数中指定的Bean,同时调用此Bean上的DisposableBean和DestructionAwareBeanPostProcessors方法
void destroyBean(Object existingBean);
//-------------------------------------------------------------------------
// Delegate methods for resolving injection points
//-------------------------------------------------------------------------
//销毁参数中指定的bean,同时调用此Bean上的DisposableBean和DestructionAwareBeanPostProcessors方法
<T> NamedBeanHolder<T> resolveNamedBean(Class<T> requiredType) throws BeansException;
//查找唯一符合指定类的实例,如果有,则返回实例的名字和实例本身
Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName) throws BeansException;
//查找唯一符合指定类的实例,如果有,则返回实例的名字和实例本身
Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName,
Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException;
}
网友评论