<!--context-param用來指定applicationContext.xml路徑 ApplicationContext為spring容器的上下文,通過上下文操作容器中bean. --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param>
<listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
<filter> <filter-name>encodingFilter</filter-name> <filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <servlet-name>springmvc</servlet-name> </filter-mapping>
<!-- DispatcherServlet預設使用WebApplicationContext作為上下文, Spring組態檔預設為「/WEB-INF/[servlet名字]-servlet.xml」 也可以通過init-param來指定 Spring組態檔路徑 --> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> <!--<init-param> <param-name>contextConfigLocation</param-name> <param-name>/WEB-INF/springmvc-servlet.xml</param-name> </init-param>--> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
總結:ServletContext是WebApplicationContext的底層支撐,所有的外界設定資訊讀到ServletContext中,然後再通過ContextLoaderListener觸發Spring根上下文的初始化
載入細節