think in spring refresh 8
refresh 方法的第8步:
创建了一个ApplicationEventMulticaster . 它的作用是什么 ??? <<<<
// Initialize event multicaster for this context. initApplicationEventMulticaster();
/** * Initialize the ApplicationEventMulticaster. * Uses SimpleApplicationEventMulticaster if none defined in the context. * @see org.springframework.context.event.SimpleApplicationEventMulticaster */ protected void initApplicationEventMulticaster() { ConfigurableListableBeanFactory beanFactory = getBeanFactory(); // 是一个 DefaultListableBeanFactory 对象 if (beanFactory.containsLocalBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) { // 本地化 ??? this.applicationEventMulticaster = beanFactory.getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class); // 创建bean实例 if (logger.isTraceEnabled()) { logger.trace("Using ApplicationEventMulticaster [" + this.applicationEventMulticaster + "]"); } } else { this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory); // 不通过IOC容器,直接new创建一个事件多播器 // 将创建的对象 添加到以及缓存中,后面可以直接使用了。 跟ioc容器创建的bean一样。
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() + "]"); } } }
也许会有遗憾,但是不应该在失败之前
浙公网安备 33010602011771号