org.springframework.context.support.AbstractApplicationContext

类图,用2张图拼接而成
spring application之AbstractApplicationContext-LMLPHPspring application之AbstractApplicationContext-LMLPHP

下面说一下各个类(接口)的作用

Closeble,AutoCloseble

Closeble jdk提供的,基于流的关闭
AutoCloseble JDK7,支持try() 自动关闭

org.springframework.context.Lifecycle 生命周期,启动与关闭

提供start()与stop()方法

org.springframework.context.ApplicationEventPublisher

事件发布体系spring application之AbstractApplicationContext-LMLPHP

SimpleApplicationEventMulticaster负责注册,删除,与发布事件,类似于观察者模式。注册事件支持beanName,所以在创建SimpleApplicationEventMulticaster``需要一个BeanFactory

ConfigurableApplicationContext

主要有以下几个方法:

void setEnvironment(ConfigurableEnvironment environment);
void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor);//BeanFactory后置处理器
void addApplicationListener(ApplicationListener<?> listener);
void addProtocolResolver(ProtocolResolver resolver);
void refresh() throws BeansException, IllegalStateException;
void registerShutdownHook();
void close();

AbstractApplicationContext

核心方法:public void refresh() throws BeansException, IllegalStateException;

prepareRefresh();//刷新准备,子类覆写
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); //组装BeanFactory
prepareBeanFactory(beanFactory);//解决BeanFactory的Bean依赖,获取并设置ApplicationListern
postProcessBeanFactory(beanFactory); //子类覆写
invokeBeanFactoryPostProcessors(beanFactory);//处理BeanFacory后置处理器registerBeanPostProcessors(beanFactory); //注册Bean后置处理器
initMessageSource();//i18ninitApplicationEventMulticaster();//事件广播器

06-08 14:38