AutowireCapableBeanFactory 根据名称:自动装配的BeanFactory,其实也是对BeanFactory的增强

//自动装配的Bean 工厂
public interface AutowireCapableBeanFactory extends BeanFactory {

     //工厂没有自动装配的Bean
    int AUTOWIRE_NO = 0;

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

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

     //根据构造方法快速装配的Bean
    int AUTOWIRE_CONSTRUCTOR = 3;
     //Bean的class内部来进行装配,Spring 3.0开始被弃用
    @Deprecated
    int AUTOWIRE_AUTODETECT = 4;

    //-------------------------------------------------------------------------
    // Typical methods for creating and populating external bean instances
    //典型的方法来创建和填充外部bean实例
    //-------------------------------------------------------------------------

    /**
     * Fully create a new bean instance of the given class.
     * <p>Performs full initialization of the bean, including all applicable
     * {@link BeanPostProcessor BeanPostProcessors}.
     * <p>Note: This is intended for creating a fresh instance, populating annotated
     * fields and methods as well as applying all standard bean initialization callbacks.
     * It does <i>not</> imply traditional by-name or by-type autowiring of properties;
     * use {@link #createBean(Class, int, boolean)} for those purposes.
     * @param beanClass the class of the bean to create
     * @return the new bean instance
     * @throws BeansException if instantiation or wiring failed
     */
     //根据bena的类型来创建Bean实例
    <T> T createBean(Class<T> beanClass) throws BeansException;

    /**
     * Populate the given bean instance through applying after-instantiation callbacks
     * and bean property post-processing (e.g. for annotation-driven injection).
     * <p>Note: This is essentially intended for (re-)populating annotated fields and
     * methods, either for new instances or for deserialized instances. It does
     * <i>not</i> imply traditional by-name or by-type autowiring of properties;
     * use {@link #autowireBeanProperties} for those purposes.
     * @param existingBean the existing bean instance
     * @throws BeansException if wiring failed
     */
     //给定对象,在后处理bean,进行自动装配
    void autowireBean(Object existingBean) throws BeansException;

     //根据Bean的BeanDefinition,来装配这个未加工的Object
    Object configureBean(Object existingBean, String beanName) throws BeansException;

    //-------------------------------------------------------------------------
    // Specialized methods for fine-grained control over the bean lifecycle
    //-------------------------------------------------------------------------

     //传入指定的Bean的类型,指定的装配的策略,是否依赖检查 来创建一个完全新的Bean
    Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;

     //类似上面
    Object autowire(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;

     //自动装配
    void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck)
            throws BeansException;

     //初始化之前执行BeanPostProcessors
    void applyBeanPropertyValues(Object existingBean, String beanName) throws BeansException;

     * <p>Note that no bean definition of the given name has to exist
     * in the bean factory. The passed-in bean name will simply be used
     * for callbacks but not checked against the registered bean definitions.
     * @param existingBean the existing bean instance
     * @param beanName the name of the bean, to be passed to it if necessary
     * (only passed to {@link BeanPostProcessor BeanPostProcessors})
     * @return the bean instance to use, either the original or a wrapped one
     * @throws BeansException if the initialization failed
     */
    Object initializeBean(Object existingBean, String beanName) throws BeansException;

    /**
     * Apply {@link BeanPostProcessor BeanPostProcessors} to the given existing bean
     * instance, invoking their {@code postProcessBeforeInitialization} methods.
     * The returned bean instance may be a wrapper around the original.
     * @param existingBean the new bean instance
     * @param beanName the name of the bean
     * @return the bean instance to use, either the original or a wrapped one
     * @throws BeansException if any post-processing failed
     * @see BeanPostProcessor#postProcessBeforeInitialization
     */
    Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
            throws BeansException;

    /**
     * Apply {@link BeanPostProcessor BeanPostProcessors} to the given existing bean
     * instance, invoking their {@code postProcessAfterInitialization} methods.
     * The returned bean instance may be a wrapper around the original.
     * @param existingBean the new bean instance
     * @param beanName the name of the bean
     * @return the bean instance to use, either the original or a wrapped one
     * @throws BeansException if any post-processing failed
     * @see BeanPostProcessor#postProcessAfterInitialization
     */
    Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
            throws BeansException;

    /**
     * Destroy the given bean instance (typically coming from {@link #createBean}),
     * applying the {@link org.springframework.beans.factory.DisposableBean} contract as well as
     * registered {@link DestructionAwareBeanPostProcessor DestructionAwareBeanPostProcessors}.
     * <p>Any exception that arises during destruction should be caught
     * and logged instead of propagated to the caller of this method.
     * @param existingBean the bean instance to destroy
     */
     //销毁指定的Bean
    void destroyBean(Object existingBean);

    //-------------------------------------------------------------------------
    // Delegate methods for resolving injection points
    //-------------------------------------------------------------------------

     //
    <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;

}

英语翻译之前的都删了,也许有些地方自己理解的不对,可以指正下,

解析下:

1.常量:5个常量,1个是判断是工厂是否自动装配bean,其他常量是对自动装配的策略。其中常量等于4的这个在Spring3.0时候进行抛弃

2.6个自动装配bean的方法,3个和BeanPostProcessors有关的处理,2个指定的分解依赖的方法,1个销毁bean的方法,1个初始化Bean的方法

这个接口其实是扩张 了Bean的自动装配方法和前后处理器BeanPostProcessors

时间: 2024-10-14 20:40:47

AutowireCapableBeanFactory 根据名称:自动装配的BeanFactory,其实也是对BeanFactory的增强的相关文章

spring:按照Bean的名称自动装配User

本实例将介绍如何按照Bean 的名称自动装配 User 对象! <bean> 元素的 autowire 属性负责自动装配 <bean> 标签,定义 JavaBean 的属性.这样做可以省去很多配置 JavaBean 属性的标签代码,使代码更整洁.美观: 但是也有负面影响:使用自动装配之后,无法从配置文件中读懂 JavaBean 需要什么属性. 1.编写User 对象,代码如下: package com.importnew; public class User { private S

Spring4-自动装配Beans-按属性名称自动装配

1.创建Maven项目,项目名称springdemo15,如图所示 2.配置Maven,修改项目中的pom.xml文件,修改内容如下 <project xmlns="http://maven.apache.org/POM/4.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0

Spring系列【10】按照Bean的名称自动装配

User.java 1 package com.lh.entity; 2 3 public class User { 4 private String name = "test"; //用户姓名 5 private Integer age = 27; //年龄 6 private String sex = "男"; //性别 7 public String getName() { 8 return name; 9 } 10 @Override 11 public S

4.AutowireCapableBeanFactory 自动装配工厂

AutowireCapableBeanFactory 根据名称:自动装配的BeanFactory,其实也是对BeanFactory的增强 源代码: /* * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in complian

Spring中的自动装配案例分析

Spring_Autowiring collaborators 在Spring3.2.2中自动装配类型,分别为:no(default)(不采用自动装配).byName,byType,constructor下面来分别介绍一下这些是如何自动装配的 <bean id="foo" class="...Foo" autowire="autowire type"> Mode Explanation no (Default) No autowiri

Spring——自动装配

基于J2EE平台的框架很多,并且大多数框架中都有着庞大复杂的配制文件,维护起来很不方便,Spring在支持配置文件时也提供了一套能让程序员偷懒的小规则:自动装配. Spring的IOC容器通过Java反射机制了解了容器中所存在Bean的配置信息,这包括构造函数方法的结构,属性的信息,而正是由于这个原因,Spring容器才能够通过某种规则来对Bean进行自动装配,而无须通过显式的方法来进行配制. 自动装配模式: 主要介绍:根据名称自动装配.根据类型自动装配. 根据名称自动装配: 根据类型自动装配:

XML 配置里的 Bean 自动装配

在XML文件中,先看一下下面的代码: <bean id="student" class="com.jeremy.spring.beans.student"> <property name="s_name" value="jeremy"></property> <property name="age" value="20"></prop

Spring4.0学习笔记(2) —— 自动装配

Spring IOC 容器可以自动装配Bean,需要做的是在<bean>的autowire属性里指定自动装配的模式 1)byType 根据类型自动装配,若IOC 容器中有多个目标Bean类型一致的Bean,Spring将无法判定哪个Bean最适合该属性,不能执行自动装配 2)byName 根据名称自动装配,必须将目标Bean名称和属性名设置的完全相同 配置方法: Address.java package com.spring.autowire; public class Address { p

Spring学习笔记 5. 尚硅谷_佟刚_Spring_自动装配

1,回顾以前的做法 一个人有姓名,有住址,有一辆车.其中住址和车也是一个类,这种情况下不用自动装配是十分容易实现的 (1)Person类 package com.zsq; public class Person { private String name; private Address address; private Car car; public String getName() { return name; } public void setName(String name) { thi