美文网首页
Spring学习笔记(一)_Spring启动过程

Spring学习笔记(一)_Spring启动过程

作者: zhyee_yan | 来源:发表于2018-05-21 22:38 被阅读0次

Web容器

Web容器用来提供程序的运行环境,以tomcat为例,在tomcat中,一个web工程存放在一个context容器中,工程中的web.xml配置了容器的属性。

Spring启动

  • 第一步:启动web项目时,容器会从web.xml中读取到所有属性,包括ContextLoaderListener等。
  • 第二步:tomcat创建ServletContext(可以理解为上述的context容器),整个web工程都可以使用这个上下文。
  • 第三步:tomcat将读取到的ContextLoaderListener等内容都提交给ServletContext。
  • 第四步:创建web.xml中配置的监听器类,在监听器类中必须要实现ServletContextListener接口。
  • 第五步:由ContextLoaderListener监听器启动Spring(ContextLoaderListener实现了用来监听ServletContext事件的ServletContextListener 这个接口,如果 ServletContext 状态发生变化,将会触发产生对应的ServletContextEvent,然后调用监听器的不同的方法。)
  • 第六步:ContextLoaderListener启动时会触发contextInitialized方法,该方法会创建Spring上下文对象WebApplicationContext,加载bean实例,并将WebApplicationContext放入servletContext中。

参考

漫谈Spring的启动与初始化

相关文章

网友评论

      本文标题:Spring学习笔记(一)_Spring启动过程

      本文链接:https://www.haomeiwen.com/subject/fgtcjftx.html