BeanFactory接口体系解读(2)

一般应用开发者不会使用这个接口,所以像ApplicationContext这样的外观实现类不会实现这个接口,如果真手痒痒可以通过ApplicationContext的getAutowireCapableBeanFactory接口获取. 

这边定义了5种自动装配策略:不注入AUTOWIRE_NO,使用bean name策略装配AUTOWIRE_BY_NAME,使用类型装配策略AUTOWIRE_BY_TYPE,使用构造器装配策略AUTOWIRE_CONSTRUCTOR,自动装配策略AUTOWIRE_AUTODETECT

  这边的自动策略是先尝试构造器,然后才是byType.这边应该是跟xml配置文件中的装配策略对应.

继续看定义的api:

  a, 创建和填充外部bean实例的典型方法

    <T> T createBean(Class<T> beanClass) throws BeansException;

    void autowireBean(Object existingBean) throws BeansException; // 使用autowireBeanProperties装配属性

    Object configureBean(Object existingBean, String beanName) throws BeansException; // 自动装配属性,填充属性值,使用诸如setBeanName,setBeanFactory这样的工厂回调填充属性,最好还要调用post processor

    Object resolveDependency(DependencyDescriptor descriptor, String beanName) throws BeansException;

  b, 在bean的生命周期进行细粒度控制的专门方法

    Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException; // 会执行bean完整的初始化,包括BeanPostProcessors和initializeBean

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

    void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck) throws BeansException;

    void applyBeanPropertyValues(Object existingBean, String beanName) throws BeansException;

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

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

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

    Object resolveDependency(DependencyDescriptor descriptor, String beanName, Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException;

--------------------------------------分割线 --------------------------------------

Spring中如何配置Hibernate事务

Struts2整合Spring方法及原理

基于 Spring 设计并实现 RESTful Web Services

Spring-3.2.4 + Quartz-2.2.0集成实例

使用 Spring 进行单元测试

运用Spring注解实现Netty服务器端UDP应用程序

Spring 3.x 企业应用开发实战 PDF完整高清扫描版+源代码

--------------------------------------分割线 --------------------------------------

3. HierarchicalBeanFactory

提供父容器的访问功能.至于父容器的设置,需要找ConfigurableBeanFactory的setParentBeanFactory(接口把设置跟获取给拆开了!).

这边可说的不多,直接上api:

  a, 获取父容器 bean factory

    BeanFactory getParentBeanFactory();

  b, 判断当前容器是否保护bean

    boolean containsLocalBean(String name);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/c5fccf149da41847b2f9622fd083c86a.html