浅谈Spring与web.xml
来源:互联网 发布:数据治理整体解决方案 编辑:程序博客网 时间:2024/05/21 07:24
在学习Spring的过程中,一个问题一直困扰着我,为啥在web.xml中写几行代码 就号称 “ 接入Spring ” 了。这几行代码又干了写什么。。下面先上一段配置,来分析分析
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>xxx</display-name> <!-- part.1 主容器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:application-pre.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- part.2 servlet容器 --> <servlet> <servlet-name>springMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <description>springmvc</description> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMvc</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping></web-app>
web.xml中主要分为两个部分一个是主容器的创建(触发点为ContextLoaderListener),一个是servlet容器的创建(触发点为DispatcherServlet)。
在ContextLoaderListener中有个contextInitialized初始化容器的方法
一开始this.context为null,接着创建ApplicationContext
调用ApplicationContext的refresh()方法
DispatcherServlet则会在父类FrameworkServlet的initServletBean中调用initWebApplicationContext方法,剩下的流程和ContextLoaderListener流程一样
这里又是那个方法,,
这样就会进入容器部分。。
最后上两张图,先后创建的ApplicationContext的serializationId是不一样的,servlet的命名后面会跟上servlet-name
End...
0 0
- 浅谈Spring与web.xml
- springMVC之web.xml,spring-mvc.xml与applicationContext.xml
- web.xml 配置Spring 与 struts
- SpringMVC与Spring整合,配置web.xml
- spring boot 之web浅谈
- 浅谈Spring与IOC
- web.xml[spring][encoding]
- Spring mvc web.xml
- spring mvc web.xml
- spring web.xml
- spring中的web.xml
- spring web.xml
- spring-web.xml
- Spring web.xml
- web。xml初始化spring
- struts2与spring整合web.xml加入的配置
- ssh整合!Struts.xml、hibernate与spring整合的applicationContext.xml、web.xml文件的配置!
- Spring源码分析 从web.xml 中ContextLoaderListener看Spring 容器与web容器联系
- Python 作业2
- 基础研究面试准备
- Android仿京东筛选
- ORAchk使用
- 学习PHP表单时的一些小问题
- 浅谈Spring与web.xml
- JDBC简介
- KMP算法
- 等价二叉树
- BZOJ 1552 [Cerc2007]robotic sort
- 配置电脑网络IP
- Java面试准备二:String、StringBuilder、StringBuffer
- 【笔试】Java中的重载与重写
- Dokcer创建私有仓库、私有仓库Web管理