Java Web项目中的一个配置文件
web.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| <web-app> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-container.xml</param-value> </context-param>
<servlet> <servlet-name>app</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc-container.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>app</servlet-name> <url-pattern>/app/*</url-pattern> </servlet-mapping> </web-app>
|
启动顺序
通过注册 Web 服务器的监听器 ContextLoaderListener, 加载 Spring 配置文件并启动;
在加载Servlet时, DispatcherServlet 引导 SpringMVC 启动;
通过启动 SpringMVC 事件加载内置组件(可覆盖 DispatcherServlet.properties 自定义配置)。
SpringBoot 中的顺序是不一样的, 是由Spring内嵌 使用 Spring 配置来引导自身和嵌入式 Servlet 容器。 Filter 和 Servlet 声明在 Spring 配置中检测到并在 Servlet 容器中注册。有关更多详细信息参阅 Spring 文档。
链接
DispatcherServlet