ContextLoaderListener

Tomcat 在进行最终调用 listener.contextInitialized,从而掉用到 ContextLoaderListener

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  5. <listener>
  6. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  7. </listener>
  8. <context-param>
  9. <param-name>contextConfigLocation</param-name>
  10. <param-value>classpath:spring/spring.xml</param-value>
  11. </context-param>
  12. <servlet>
  13. <servlet-name>DispatcherServlet</servlet-name>
  14. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  15. <init-param>
  16. <param-name>contextConfigLocation</param-name>
  17. <param-value>classpath:spring-servlet.xml</param-value>
  18. </init-param>
  19. <load-on-startup>1</load-on-startup>
  20. </servlet>
  21. <servlet-mapping>
  22. <servlet-name>DispatcherServlet</servlet-name>
  23. <url-pattern>*.do</url-pattern>
  24. </servlet-mapping>
  25. </web-app>

ContextLoaderListener 主要是为了创建并刷新父容器(IOC),其实现类是 XmlWebApplicationContext

DispatcherServlet

init():创建子容器

DispatcherServlet => FrameworkServlet => HttpServletBean.init(),完成创建子容器

onRefresh():初始化九大组件

初始化九大组件