1

AutowireCapableBeanFactory实现了BeanFactory接口,负责bean生命周期的管理。我们先看看几个常量

类结构

image.png

字段

int AUTOWIRE_NO = 0;//表示没有外部定义的自动装配
int AUTOWIRE_BY_NAME = 1;//通过名称指示自动装配bean属性(适用于Bean所有属性的setter)
int AUTOWIRE_BY_TYPE = 2;//通过类型指示自动装配bean属性(适用于Bean所有属性的setter)
int AUTOWIRE_CONSTRUCTOR = 3;//构造函数
int AUTOWIRE_AUTODETECT = 4;//通过bean类的内省确定适当的自动装配策略,已弃用
String ORIGINAL_INSTANCE_SUFFIX = ".ORIGINAL";//用于没有代理的时候,也能强制返回实例

方法解析

bean的创建

//autowireMode就是上面的常量,dependencyCheck是否对依赖进行检查
Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;
<T> T createBean(Class<T> beanClass) throws BeansException;

bean的初始化

Object initializeBean(Object existingBean, String beanName) throws BeansException;

bean的后置处理器

Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
            throws BeansException;
Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
            throws BeansException;

bean的销毁

void destroyBean(Object existingBean);

自动装配bean

Object autowire(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;
void autowireBean(Object existingBean) throws BeansException;
void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck)
            throws BeansException;

配置bean

Object configureBean(Object existingBean, String beanName) throws BeansException;

解析bean

Object resolveBeanByName(String name, DependencyDescriptor descriptor) throws BeansException;
Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException;
Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName,
            @Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException;
<T> NamedBeanHolder<T> resolveNamedBean(Class<T> requiredType) throws BeansException;

大军
847 声望183 粉丝

学而不思则罔,思而不学则殆