configurablebeanfactory

在这里插入图片描述
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();}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/249519.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

外观模式

一、什么是外观模式   有些人可能炒过股票&#xff0c;但其实大部分人都不太懂&#xff0c;这种没有足够了解证券知识的情况下做股票是很容易亏钱的&#xff0c;刚开始炒股肯定都会想&#xff0c;如果有个懂行的帮帮手就好&#xff0c;其实基金就是个好帮手&#xff0c;支付宝…

OC内存管理

OC内存管理 一、基本原理 &#xff08;一&#xff09;为什么要进行内存管理。 由于移动设备的内存极其有限&#xff0c;所以每个APP所占的内存也是有限制的&#xff0c;当app所占用的内存较多时&#xff0c;系统就会发出内存警告&#xff0c;这时需要回收一些不需要再继续使用的…

面试题集锦

1. L1范式和L2范式的区别 (1) L1范式是对应参数向量绝对值之和 (2) L1范式具有稀疏性 (3) L1范式可以用来作为特征选择&#xff0c;并且可解释性较强&#xff08;这里的原理是在实际Loss function 中都需要求最小值&#xff0c;根据L1的定义可知L1最小值只有0&#xff0c;故可以…

Spring注解配置工作原理源码解析

一、背景知识 在【Spring实战】Spring容器初始化完成后执行初始化数据方法一文中说要分析其实现原理&#xff0c;于是就从源码中寻找答案&#xff0c;看源码容易跑偏&#xff0c;因此应当有个主线&#xff0c;或者带着问题、目标去看&#xff0c;这样才能最大限度的提升自身代…

Spring--Context

应用上下文 Spring通过应用上下文&#xff08;Application Context&#xff09;装载bean的定义并把它们组装起来。Spring应用上下文全权负责对象的创建和组装。Spring自带了多种应用上下文的实现&#xff0c;它们之间主要的区别仅仅在于如何加载配置。 1.AnnotationConfigApp…

了解PID控制

2019-03-07 【小记】 了解PID控制 比例 - 积分 - 微分 积分 --- 记忆过去 比例 --- 了解现在 微分 --- 预测未来 转载于:https://www.cnblogs.com/skullboyer/p/10487884.html

program collections

Java byte & 0xff byte[] b new byte[1];b[0] -127;System.out.println("b[0]:"b[0]"; b[0]&0xff:"(b[0] & 0xff));//output:b[0]:-127; b[0]&0xff:129计算机内二进制都是补码形式存储&#xff1a; b[0]: 补码&#xff0c;10000001&…

Spring ConfigurationClassPostProcessor Bean解析及自注册过程

一bean的自注册过程 二,自注册过程说明 1 configurationclassparser解析流程 1、处理PropertySources注解&#xff0c;配置信息的解析 2、处理ComponentScan注解&#xff1a;使用ComponentScanAnnotationParser扫描basePackage下的需要解析的类(SpringBootApplication注解也包…

2019第二周作业

基础作业 实验代码 #include<stdlib.h> int main(void) {FILE*fp;int num[4],i,b,max;char op;if((fpfopen("c:\\tmj.txt","r"))NULL){ printf("File open error!\n"); exit(0);}for(i0;i<4;i){fscanf(fp,"%d%c",&nu…

实验一(高见老师收)

学 号201521450016 中国人民公安大学 Chinese people’ public security university 网络对抗技术 实验报告 实验一 网络侦查与网络扫描 学生姓名 陈璪琛 年级 2015 区队 五 指导教师 高见 信息技术与网络安全学院 2018年9月18日 实验任务总纲 2018—2019学年…

Spring 钩子之BeanFactoryPostProcessor和BeanPostProcessor

BeanFactoryPostProcessor和BeanPostProcessor这两个接口都是初始化bean时对外暴露的入口之一&#xff0c;和Aware类似&#xff08;PS:关于spring的hook可以看看Spring钩子方法和钩子接口的使用详解讲的蛮详细&#xff09;本文也主要是学习具体的钩子的细节&#xff0c;以便于实…

什么是HTML DOM对象

HTML DOM 对象 HTML DOM Document 对象 Document 对象 每个载入浏览器的 HTML 文档都会成为 Document 对象。 Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问。 提示&#xff1a;Document 对象是 Window 对象的一部分&#xff0c;可通过 window.document 属…

Python3 matplotlib的绘图函数subplot()简介

Python3 matplotlib的绘图函数subplot()简介 一、简介 matplotlib下, 一个 Figure 对象可以包含多个子图(Axes), 可以使用 subplot() 快速绘制, 其调用形式如下 : subplot(numRows, numCols, plotNum) 图表的整个绘图区域被分成 numRows 行和 numCols 列 然后按照从左到右&…

signal(SIGHUP, SIG_IGN);

signal(SIGHUP, SIG_IGN); 的理解转载于:https://www.cnblogs.com/lanjiangzhou/p/10505653.html

spring钩子

Spring钩子方法和钩子接口的使用详解 前言 SpringFramework其实具有很高的扩展性&#xff0c;只是很少人喜欢挖掘那些扩展点&#xff0c;而且官方的Refrence也很少提到那些Hook类或Hook接口&#xff0c;至于是不是Spring官方有意为之就不得而知。本文浅析一下笔者目前看到的S…

day 012 生成器 与 列表推导式

生成器的本质就是迭代器&#xff0c;写法和迭代器不一样&#xff0c;用法一样。 获取方法&#xff1a; 1、通过生成器函数 2、通过各种推导式来实现生成器 3、通过数据的转换也可以获取生成器 例如&#xff1a; 更改return 为 yield 即成为生成器 该函数就成为了一个生成器函数…

20172325 2018-2019-1 《Java程序设计》第二周学习总结

20172325 2018-2019-1 《Java程序设计》第二周学习总结 教材学习内容总结 3.1集合 集合是一种聚集、组织了其他对象的对象。集合可以分为两大类&#xff1a;线性集合和非线性集合。线性集合&#xff1a;一种其元素按照直线方式组织的集合。非线性集合&#xff1a;一种其元素按某…

题解 luogu P2568 GCD

题解 luogu P2568 GCD 时间&#xff1a;2019.3.11 欧拉函数前缀和 题目描述 给定整数\(N\)&#xff0c;求\(1\le x,y \le N\)且\(\gcd(x,y)\)为素数的数对\((x,y)\)有多少对. 分析 枚举素数\(p\), 先求出\(1\le x,y \le \left \lfloor \dfrac n p \right \rfloor\)且\(\gcd(x, …

解决前后台发送请求或者接口之间发送请求乱码的问题

前后台传中文乱码&#xff1a; 前台使用encodeURI 进行编码 后台使用decode进行解码 如果接口之间调用出现乱码.接收方是&#xff1f;&#xff1f;&#xff1f;&#xff1f;这种。传送方式明文的处理方式&#xff1a; 发送方使用decode 进行编码&#xff1a; 接收方使用的ecod…

.net Core发布至IIS完全手册带各种踩坑

服务器环境配置 和各位大爷报告一下我的服务器环境 : Windows Server 2012 iis 8 小插曲开始: 运维大哥在昨天给了我一台新的server 0环境开始搭建 。 并且没有安装任何的系统补丁。 第一件事情请开始打 补丁 打完补丁之后有时补丁会不完全 ,所以需要去官网获取补丁: KB2919355…