ConfigurableBeanFactory定义BeanFactory的配置.ConfigurableBeanFactory中定义了太多太多的api,比如类加载器,类型转化,属性编辑器,BeanPostProcessor,作用域,bean定义,处理bean依赖关系,合并其他ConfigurableBeanFactory,bean如何销毁.

ConfigurableBeanFactory同时继承了HierarchicalBeanFactory 和 SingletonBeanRegistry 这两个接口,即同时继承了分层和单例类注册的功能。

具体:

1、2个静态不可变常量分别代表单例类和原型类。

2、1个设置父工厂的方法,跟HierarchicalBeanFactory接口的getParentBeanFactory方法互补。

3、4个跟类加载器有关的方法:get/set工厂类加载器和get/set临时类加载器。

4、2个设置、是否缓存元数据的方法(热加载开关)。

5、11个处理Bean注册、加载等细节的方法,包括:Bean表达式分解器、转换服务、属性编辑登记员、属性编辑器、属性编辑注册器、类型转换器、嵌入式的字符串分解器

6、2个处理Bean后处理器的方法。

7、3个跟注册范围相关的方法。

8、1个返回安全访问上下文的方法、1个从其他的工厂复制相关的所有配置的方法。

9、2个跟Bean别名相关的方法、1个返回合并后的Bean定义的方法。

10、1个判断是否为工厂Bean的方法、2个跟当前Bean创建时机相关的方法。

11、3个跟Bean依赖相关的方法、3个销毁Bean相关的方法。

总结:这个巨大的工厂接口,继承自HierarchicalBeanFactory 和 SingletonBeanRegistry 这两个接口,并额外独有37个方法!!!(看的我都快疯了…)这37个方法包含了工厂创建、注册一个Bean的众多细节。这个工厂名为ConfigurableBeanFactory,真是名不虚传!统计一下此时的ConfigurableBeanFactory的方法数吧。自有的37个方法、HierarchicalBeanFactory的2个方法、SingletonBeanRegistry的5个方法、爷爷接口BeanFactory的10个方法,共有54个方法!虽然方法繁多,还算井井有条!

/*** Configuration interface to be implemented by most bean factories. Provides* facilities to configure a bean factory, in addition to the bean factory* client methods in the {@link org.springframework.beans.factory.BeanFactory}* interface.** <p>This bean factory interface is not meant to be used in normal application* code: Stick to {@link org.springframework.beans.factory.BeanFactory} or* {@link org.springframework.beans.factory.ListableBeanFactory} for typical* needs. This extended interface is just meant to allow for framework-internal* plug'n'play and for special access to bean factory configuration methods.** @author Juergen Hoeller* @since 03.11.2003* @see org.springframework.beans.factory.BeanFactory* @see org.springframework.beans.factory.ListableBeanFactory* @see ConfigurableListableBeanFactory*/
/*** 定义BeanFactory的配置.* * 这边定义了太多太多的api,比如类加载器,类型转化,属性编辑器,BeanPostProcessor,作用域,bean定义,处理bean依赖关系,合并其他ConfigurableBeanFactory,bean如何销毁.* * @author DemoTransfer* @since 4.3*/
public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, SingletonBeanRegistry {//-------------------------------------------------------------------------// 定义了两个作用域: 单例和原型.可以通过registerScope来添加.// SCOPE_SINGLETON,SCOPE_PROTOTYPE//-------------------------------------------------------------------------/*** Scope identifier for the standard singleton scope: "singleton".* Custom scopes can be added via {@code registerScope}.* @see #registerScope*///  单例String SCOPE_SINGLETON = "singleton";/*** Scope identifier for the standard prototype scope: "prototype".* Custom scopes can be added via {@code registerScope}.* @see #registerScope*///  原型String SCOPE_PROTOTYPE = "prototype";/*** Set the parent of this bean factory.* <p>Note that the parent cannot be changed: It should only be set outside* a constructor if it isn't available at the time of factory instantiation.* @param parentBeanFactory the parent BeanFactory* @throws IllegalStateException if this factory is already associated with* a parent BeanFactory* @see #getParentBeanFactory()*/// 父容器设置.而且一旦设置了就不让修改/** 搭配HierarchicalBeanFactory接口的getParentBeanFactory方法*/void setParentBeanFactory(BeanFactory parentBeanFactory) throws IllegalStateException;/*** Set the class loader to use for loading bean classes.* Default is the thread context class loader.* <p>Note that this class loader will only apply to bean definitions* that do not carry a resolved bean class yet. This is the case as of* Spring 2.0 by default: Bean definitions only carry bean class names,* to be resolved once the factory processes the bean definition.* @param beanClassLoader the class loader to use,* or {@code null} to suggest the default class loader*/// 类加载器设置与获取.默认使用当前线程中的类加载器/** 设置、返回工厂的类加载器*/void setBeanClassLoader(ClassLoader beanClassLoader);/*** Return this factory's class loader for loading bean classes.*/// 类加载器设置与获取.默认使用当前线程中的类加载器ClassLoader getBeanClassLoader();/*** Specify a temporary ClassLoader to use for type matching purposes.* Default is none, simply using the standard bean ClassLoader.* <p>A temporary ClassLoader is usually just specified if* <i>load-time weaving</i> is involved, to make sure that actual bean* classes are loaded as lazily as possible. The temporary loader is* then removed once the BeanFactory completes its bootstrap phase.* @since 2.5*/// 为了类型匹配,搞个临时类加载器.好在一般情况为null,使用上面定义的标准加载器/** 设置、返回一个临时的类加载器*/void setTempClassLoader(ClassLoader tempClassLoader);/*** Return the temporary ClassLoader to use for type matching purposes,* if any.* @since 2.5*/// 为了类型匹配,搞个临时类加载器.好在一般情况为null,使用上面定义的标准加载器ClassLoader getTempClassLoader();/*** Set whether to cache bean metadata such as given bean definitions* (in merged fashion) and resolved bean classes. Default is on.* <p>Turn this flag off to enable hot-refreshing of bean definition objects* and in particular bean classes. If this flag is off, any creation of a bean* instance will re-query the bean class loader for newly resolved classes.*/// 是否需要缓存bean metadata,比如bean difinition 和 解析好的classes.默认开启缓存/** 设置、是否缓存元数据,如果false,那么每次请求实例,都会从类加载器重新加载(热加载)*/void setCacheBeanMetadata(boolean cacheBeanMetadata);/*** Return whether to cache bean metadata such as given bean definitions* (in merged fashion) and resolved bean classes.*/// 是否需要缓存bean metadata,比如bean difinition 和 解析好的classes.默认开启缓存// 是否缓存元数据boolean isCacheBeanMetadata();/*** Specify the resolution strategy for expressions in bean definition values.* <p>There is no expression support active in a BeanFactory by default.* An ApplicationContext will typically set a standard expression strategy* here, supporting "#{...}" expressions in a Unified EL compatible style.* @since 3.0*/// 定义用于解析bean definition的表达式解析器/** Bean表达式分解器*/void setBeanExpressionResolver(BeanExpressionResolver resolver);/*** Return the resolution strategy for expressions in bean definition values.* @since 3.0*/// 定义用于解析bean definition的表达式解析器BeanExpressionResolver getBeanExpressionResolver();/*** Specify a Spring 3.0 ConversionService to use for converting* property values, as an alternative to JavaBeans PropertyEditors.* @since 3.0*/// 类型转化器/** 设置、返回一个转换服务*/void setConversionService(ConversionService conversionService);/*** Return the associated ConversionService, if any.* @since 3.0*/// 类型转化器ConversionService getConversionService();/*** Add a PropertyEditorRegistrar to be applied to all bean creation processes.* <p>Such a registrar creates new PropertyEditor instances and registers them* on the given registry, fresh for each bean creation attempt. This avoids* the need for synchronization on custom editors; hence, it is generally* preferable to use this method instead of {@link #registerCustomEditor}.* @param registrar the PropertyEditorRegistrar to register*/// 属性编辑器/** 设置属性编辑登记员...*/void addPropertyEditorRegistrar(PropertyEditorRegistrar registrar);/*** Register the given custom property editor for all properties of the* given type. To be invoked during factory configuration.* <p>Note that this method will register a shared custom editor instance;* access to that instance will be synchronized for thread-safety. It is* generally preferable to use {@link #addPropertyEditorRegistrar} instead* of this method, to avoid for the need for synchronization on custom editors.* @param requiredType type of the property* @param propertyEditorClass the {@link PropertyEditor} class to register*/// 属性编辑器/** 注册常用属性编辑器*/void registerCustomEditor(Class<?> requiredType, Class<? extends PropertyEditor> propertyEditorClass);/*** Initialize the given PropertyEditorRegistry with the custom editors* that have been registered with this BeanFactory.* @param registry the PropertyEditorRegistry to initialize*/// 属性编辑器/** 用工厂中注册的通用的编辑器初始化指定的属性编辑注册器*/void copyRegisteredEditorsTo(PropertyEditorRegistry registry);/*** Set a custom type converter that this BeanFactory should use for converting* bean property values, constructor argument values, etc.* <p>This will override the default PropertyEditor mechanism and hence make* any custom editors or custom editor registrars irrelevant.* @see #addPropertyEditorRegistrar* @see #registerCustomEditor* @since 2.5*/// BeanFactory用来转换bean属性值或者参数值的自定义转换器/** 设置、得到一个类型转换器*/void setTypeConverter(TypeConverter typeConverter);/*** Obtain a type converter as used by this BeanFactory. This may be a fresh* instance for each call, since TypeConverters are usually <i>not</i> thread-safe.* <p>If the default PropertyEditor mechanism is active, the returned* TypeConverter will be aware of all custom editors that have been registered.* @since 2.5*/// BeanFactory用来转换bean属性值或者参数值的自定义转换器TypeConverter getTypeConverter();/*** Add a String resolver for embedded values such as annotation attributes.* @param valueResolver the String resolver to apply to embedded values* @since 3.0*/// string值解析器(想起mvc中的ArgumentResolver了)/** 增加一个嵌入式的StringValueResolver*/void addEmbeddedValueResolver(StringValueResolver valueResolver);/*** Determine whether an embedded value resolver has been registered with this* bean factory, to be applied through {@link #resolveEmbeddedValue(String)}.* @since 4.3*/boolean hasEmbeddedValueResolver();/*** Resolve the given embedded value, e.g. an annotation attribute.* @param value the value to resolve* @return the resolved value (may be the original value as-is)* @since 3.0*/// string值解析器(想起mvc中的ArgumentResolver了)//分解指定的嵌入式的值String resolveEmbeddedValue(String value);/*** Add a new BeanPostProcessor that will get applied to beans created* by this factory. To be invoked during factory configuration.* <p>Note: Post-processors submitted here will be applied in the order of* registration; any ordering semantics expressed through implementing the* {@link org.springframework.core.Ordered} interface will be ignored. Note* that autodetected post-processors (e.g. as beans in an ApplicationContext)* will always be applied after programmatically registered ones.* @param beanPostProcessor the post-processor to register*/// BeanPostProcessor用于增强bean初始化功能//设置一个Bean后处理器void addBeanPostProcessor(BeanPostProcessor beanPostProcessor);/*** Return the current number of registered BeanPostProcessors, if any.*///返回Bean后处理器的数量int getBeanPostProcessorCount();/*** Register the given scope, backed by the given Scope implementation.* @param scopeName the scope identifier* @param scope the backing Scope implementation*/// 作用域定义//注册范围void registerScope(String scopeName, Scope scope);/*** Return the names of all currently registered scopes.* <p>This will only return the names of explicitly registered scopes.* Built-in scopes such as "singleton" and "prototype" won't be exposed.* @return the array of scope names, or an empty array if none* @see #registerScope*/// 作用域定义//返回注册的范围名String[] getRegisteredScopeNames();/*** Return the Scope implementation for the given scope name, if any.* <p>This will only return explicitly registered scopes.* Built-in scopes such as "singleton" and "prototype" won't be exposed.* @param scopeName the name of the scope* @return the registered Scope implementation, or {@code null} if none* @see #registerScope*/// 作用域定义//返回指定的范围Scope getRegisteredScope(String scopeName);/*** Provides a security access control context relevant to this factory.* @return the applicable AccessControlContext (never {@code null})* @since 3.0*/// 访问权限控制//返回本工厂的一个安全访问上下文AccessControlContext getAccessControlContext();/*** Copy all relevant configuration from the given other factory.* <p>Should include all standard configuration settings as well as* BeanPostProcessors, Scopes, and factory-specific internal settings.* Should not include any metadata of actual bean definitions,* such as BeanDefinition objects and bean name aliases.* @param otherFactory the other BeanFactory to copy from*/// 合并其他ConfigurableBeanFactory的配置,包括上面说到的BeanPostProcessor,作用域等//从其他的工厂复制相关的所有配置void copyConfigurationFrom(ConfigurableBeanFactory otherFactory);/*** Given a bean name, create an alias. We typically use this method to* support names that are illegal within XML ids (used for bean names).* <p>Typically invoked during factory configuration, but can also be* used for runtime registration of aliases. Therefore, a factory* implementation should synchronize alias access.* @param beanName the canonical name of the target bean* @param alias the alias to be registered for the bean* @throws BeanDefinitionStoreException if the alias is already in use*/// bean定义处理// 注册别名/** 给指定的Bean注册别名*/void registerAlias(String beanName, String alias) throws BeanDefinitionStoreException;/*** Resolve all alias target names and aliases registered in this* factory, applying the given StringValueResolver to them.* <p>The value resolver may for example resolve placeholders* in target bean names and even in alias names.* @param valueResolver the StringValueResolver to apply* @since 2.5*/// bean定义处理//根据指定的StringValueResolver移除所有的别名void resolveAliases(StringValueResolver valueResolver);/*** Return a merged BeanDefinition for the given bean name,* merging a child bean definition with its parent if necessary.* Considers bean definitions in ancestor factories as well.* @param beanName the name of the bean to retrieve the merged definition for* @return a (potentially merged) BeanDefinition for the given bean* @throws NoSuchBeanDefinitionException if there is no bean definition with the given name* @since 2.5*/// bean定义处理// 合并bean定义,包括父容器的/** 返回指定Bean合并后的Bean定义*/BeanDefinition getMergedBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;/*** Determine whether the bean with the given name is a FactoryBean.* @param name the name of the bean to check* @return whether the bean is a FactoryBean* ({@code false} means the bean exists but is not a FactoryBean)* @throws NoSuchBeanDefinitionException if there is no bean with the given name* @since 2.5*/// bean定义处理// 是否是FactoryBean类型//判断指定Bean是否为一个工厂Beanboolean isFactoryBean(String name) throws NoSuchBeanDefinitionException;/*** Explicitly control the current in-creation status of the specified bean.* For container-internal use only.* @param beanName the name of the bean* @param inCreation whether the bean is currently in creation* @since 3.1*/// bean创建状态控制.在解决循环依赖时有使用//设置一个Bean是否正在创建void setCurrentlyInCreation(String beanName, boolean inCreation);/*** Determine whether the specified bean is currently in creation.* @param beanName the name of the bean* @return whether the bean is currently in creation* @since 2.5*/// bean创建状态控制.在解决循环依赖时有使用//返回指定Bean是否已经成功创建boolean isCurrentlyInCreation(String beanName);/*** Register a dependent bean for the given bean,* to be destroyed before the given bean is destroyed.* @param beanName the name of the bean* @param dependentBeanName the name of the dependent bean* @since 2.5*/// 处理bean依赖问题//注册一个依赖于指定bean的Beanvoid registerDependentBean(String beanName, String dependentBeanName);/*** Return the names of all beans which depend on the specified bean, if any.* @param beanName the name of the bean* @return the array of dependent bean names, or an empty array if none* @since 2.5*/// 处理bean依赖问题//返回依赖于指定Bean的所欲Bean名String[] getDependentBeans(String beanName);/*** Return the names of all beans that the specified bean depends on, if any.* @param beanName the name of the bean* @return the array of names of beans which the bean depends on,* or an empty array if none* @since 2.5*/// 处理bean依赖问题//返回指定Bean依赖的所有Bean名String[] getDependenciesForBean(String beanName);/*** Destroy the given bean instance (usually a prototype instance* obtained from this factory) according to its bean definition.* <p>Any exception that arises during destruction should be caught* and logged instead of propagated to the caller of this method.* @param beanName the name of the bean definition* @param beanInstance the bean instance to destroy*/// bean生命周期管理-- 销毁bean//销毁指定的Beanvoid destroyBean(String beanName, Object beanInstance);/*** Destroy the specified scoped bean in the current target scope, if any.* <p>Any exception that arises during destruction should be caught* and logged instead of propagated to the caller of this method.* @param beanName the name of the scoped bean*/// bean生命周期管理-- 销毁bean//销毁指定的范围Beanvoid destroyScopedBean(String beanName);/*** Destroy all singleton beans in this factory, including inner beans that have* been registered as disposable. To be called on shutdown of a factory.* <p>Any exception that arises during destruction should be caught* and logged instead of propagated to the caller of this method.*/// bean生命周期管理-- 销毁bean//销毁所有的单例类void destroySingletons();}

configurablebeanfactory相关推荐

  1. Spring : ConfigurableBeanFactory 配置能力

    1.美图 2.概述 扩展了HierarchicalBeanFactory,SingletonBeanRegistry,主要提供了对BeanFactory的配置能力 该接口扩展的内容较多,比如类加载器, ...

  2. 【spring源码分析】IOC容器初始化(六)

    前言:经过前几篇文章的讲解,我们已经得到了BeanDefinition,接下来将分析Bean的加载. 获取Bean的入口:AbstractApplicationContext#getBean 1 pu ...

  3. spring springboot springcloud常用注解

    @SpringBootApplication 组合注解,用在启动类上,源码: @Retention(RetentionPolicy.RUNTIME) @SpringBootConfiguration ...

  4. Spring4实战学习笔记

    <Spring4实战 第4版>2016年4月新出版的,之前的第三版看起来还是不错的,所以看到新版就直接买下来. 英文版源码地址:Spring in Action, Fourth Editi ...

  5. Spring 学习笔记

    Spring 的 Ioc 容器 所有的组件都是被动的( Passive),所有的组件初始化和调用都由容器负责.组件处在一个容器当中,由容器负责管理. BeanFactory 根据配置文件确定容器中 b ...

  6. 40 个 Spring Boot 常用注解

    以下文章来源方志朋的博客,回复"666"获面试宝典 作者 | 谭朝红 链接 | ramostear.com 一.Spring Web MVC 与 Spring Bean 注解 Sp ...

  7. 40 个 SpringBoot 常用注解

    以下文章来源方志朋的博客,回复"666"获面试宝典 来源:https://ramostear.com/ 一.Spring Web MVC 与 Spring Bean 注解 Spri ...

  8. 惊呆了,Spring中竟然有12种定义bean的方法

    前言 在庞大的 Java 技术体系中,Spring 有着举足轻重的地位,它给每位开发者带来了极大的便利和惊喜. 我们都知道 Spring 是创建和管理bean的工厂,它提供了多种方式定义 bean,能 ...

  9. springboot集成rabbitMQ安装+代码

    环境安装 本机电脑是mac,所以直接在终端下(无论在哪个目录下都不影响)输入 brew install erlang,先装erlang,不然rabbitmq装了跑不了,接下来就是等待的时刻.... 装 ...

最新文章

  1. 纯数学教程 Page 325 例LXVIII (13)
  2. python until语句_Python3 循环
  3. adb logcat通过包名过滤(dos命令find后跟变量)
  4. 删除一个目录及其子目录下的所有.svn文件
  5. eclipes创建一个web项目web.xml不能自动更新的原因(web.xml和@WebServlet的作用)
  6. 浅析权限认证中的有状态和无状态
  7. Intel 64/x86_64/IA-32/x86处理器 - 锁原子操作(2) - 总线封锁/缓存封锁
  8. 创建库文件c语言,创建自己的函数库
  9. java 请求webservice_JAVA调用WebService实例
  10. 减治法——生成组合对象
  11. 非线性拟合matlab代码,Matlab非线性拟合
  12. OpenCV 3.0 高动态范围图像
  13. OpenCV零基础从配置环境到读取图片,输出各种灰度腐蚀图,最后输出直方图,做矩阵运算等等
  14. html页面中文本框的光标控制
  15. 复盘2020年全球医疗行业:新冠疫苗争分夺秒、跨国药企押注中国、药企整合并购不断 | 医药观察...
  16. Zabbix发送带附件的邮件
  17. 2021蓝桥杯省赛b题解
  18. el-table筛选数据
  19. 如果编写 if 时不带 else
  20. 关于彦阳APP 相关参数说明

热门文章

  1. seo黑帽劫持用的php,黑帽seo 论坛:黑帽seo防止网站被k的js劫持跳转代码
  2. fluent python 第二版_Fluent Python 笔记(二):序列基础
  3. php撒意思,php表示是什么意思
  4. imp oracle full,Oracle 10g imp 之 full database (转官档)
  5. UnityShader RenderTypeQueue 渲染顺序
  6. UVA572 Oil Deposits DFS求解
  7. [BZOJ4698][SDOI2008]Sandy的卡片(后缀自动机)
  8. 51Nod 蜥蜴和地下室(搜索)
  9. centos系统设置局域网静态IP
  10. Oracle优化-表设计