本人本科毕业,21届毕业生,一年工作经验,简历专业技能如下,现根据简历,并根据所学知识复习准备面试。
记录日期:2022.1.4
大部分知识点只做大致介绍,具体内容根据推荐博文链接进行详细复习。
文章目录
框架原理 - Spring(十)之Spring IOC 源码initApplicationEventMulticaster()
AbstractApplicationContext#initApplicationEventMulticaster()
初始化事件监听多路广播器。
内容非常简单,先判断有没有自定义的 ApplicationEventMulticaster,没有的话就注册一个。
SimpleApplicationEventMulticaster 就是用来发布事件用的。
protected void initApplicationEventMulticaster() {
// 获取Bean工厂,一般是DefaultListBeanFactory
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
// 判断容器中是否存在beanName为"applicationEventMulticaster"的bean实例
if (beanFactory.containsLocalBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) {
// 如果存在实现ApplicationEventMulticaster接口的自定义的事件监听多路广播器。
this.applicationEventMulticaster =
beanFactory.getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class);
if (logger.isTraceEnabled()) {
logger.trace("Using ApplicationEventMulticaster [" + this.applicationEventMulticaster + "]");
}
}
else {
// 如果没有,则默认采用SimpleApplicationEventMulticaster
this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory);
// 注册进beanFactory
beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster);
if (logger.isTraceEnabled()) {
logger.trace("No '" + APPLICATION_EVENT_MULTICASTER_BEAN_NAME + "' bean, using " +
"[" + this.applicationEventMulticaster.getClass().getSimpleName() + "]");
}
}
}
事件的执行主要是在Bean初始化之后;就是publishEvent方法,在后面会讲。

京公网安备 11010502036488号