Spring管理bean:
1.从web.xml里面配置的ContextLoaderListener开始。
2.ContextLoaderListener继承ContextLoader
3.执行ContextLoaderListener的contextInitialized方法,获得servletContext.
4.把servletContext传入ContextLoader的initWebApplicationContext(ServletContext servletContext)方法并执行。
5.通过ContextLoader.createWebApplicationContext(servletContext)获得this.context(WebApplicationContext)实例。
默认情况下这个context就是XmlWebApplicationContext。
这个XmlWebApplicationContext继承一个AbstractApplicationContext类。
再执行ContextLoader.configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc)方法,
执行AbstractApplicationContext的.refresh();方法
这个方法 完成了WebApplicationContext里面的beanfactory的初始化和bean载入,beanfactorypostprocessor的调用,beanpostprocessor的注册,ApplicationEvent的监听和注册,non-lazy-init的bean的初始化。
换言之,已经把该准备的都准备好了,只需要有请求来获取bean,就根据情况或返回已经初始化的bean或进行bean的Instantiation 和 Initialization。