spring的加载过程(web) (9)--registerListeners 检测监听器bean并且注册他们
方法定义:添加实现了ApplicationListener作为监听器的bean.不影响其他监听器,那些没有被添加的的bean.
1)首先注册静态的特殊监听器。
2)添加根据ListableBeanFactory#getBeansOfType(Class type, boolean includePrototypes, boolean allowEagerInit)方法,返回的实现了ApplicationListener接口的bean.包括设置了prototype的bean
//======================================================================
ListableBeanFactory#getBeansOfType(Class type, boolean includePrototypes, boolean allowEagerInit)
返回与规定的实体类型(包括子类)相配的bean实例, 在FactoryBeans情况下从bean定义或者getObjectType的值判断。 第二个参数设定是否包含设置了pototype类型的bean,第三个参数是设定是否初始化bean.
DefaultListableBeanFactory#getBeansOfType(Class type, boolean includePrototypes, boolean allowEagerInit)类默认实现。
实际调用getBeanNamesForType(Class type, boolean includePrototypes, boolean allowEagerInit)
//复杂...,略过..
1)检查所有bean定义。循环判断没一个bean定义.
<1>首先判断是否是别名。
2)检查单例,捕获手动注册的单例.
//getBeansOfType把getBeanNamesForType结果转换。
3)把String[] 转换为map.
本文详细介绍了Spring框架中监听器的注册过程,包括静态特殊监听器的注册及通过ListableBeanFactory获取实现了ApplicationListener接口的bean,并探讨了getBeansOfType方法的具体实现。
1万+

被折叠的 条评论
为什么被折叠?



