webApplication的理解以及对应的配置解读
来源:互联网 发布:淘宝联盟能贷款吗 编辑:程序博客网 时间:2024/06/05 18:45
转载来源地址
一、先说ServletContext
javaee标准规定了,servlet容器需要在应用项目启动时,给应用项目初始化一个ServletContext作为公共环境容器存放公共信息。ServletContext中的信息都是由容器提供的。
举例:
<context-param> <param-name>key</param-name> <param-value>value123</param-value></context-param><listener> <listener-class>com.brolanda.contextlistener.listener.ContextListenerTest</listener-class></listener>
package com.brolanda.contextlistener.listener;import javax.servlet.ServletContext;import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;public class ContextListenerTest implements ServletContextListener { public void contextDestroyed(ServletContextEvent event) { System.out.println("*************destroy ContextListener*************"); } @SuppressWarnings("unused") public void contextInitialized(ServletContextEvent event) { System.out.println("*************init ContextListener*************"); ServletContext servletContext = event.getServletContext(); System.out.println("key:"+servletContext.getInitParameter("key")); } }
执行流程:
web.xml在<context-param></context-param>标签中声明应用范围内的初始化参数
3.容器将<context-param></context-param>转化为键值对,并交给ServletContext.
5.在监听中会有contextInitialized(ServletContextEvent event)初始化方法
“context-param的值” = ServletContext.getInitParameter("context-param的键");
二、spring上下文容器配置
spring为我们提供了实现ServletContextListener接口的上下文初始化监听器:org.springframework.web.context.ContextLoaderListener
spring为我们提供的IOC容器,需要我们指定容器的配置文件,然后由该监听器初始化并创建该容器。要求你指定配置文件的地址及文件名称,一定要使用:contextConfigLocation作为参数名称。
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml,/WEB-INF/jason-servlet.xml</param-value></context-param><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
该监听器,默认读取/WEB-INF/下的applicationContext.xml文件。但是通过context-param指定配置文件路径后,便会去你指定的路径下读取对应的配置文件,并进行初始化。
三、spring上下文容器配置后,初始化了什么?
既然,ServletContext是由Servlet容器初始化的,那spring的ContextLoaderListener又做了什么初始化呢?
四、spring配置时:<context:exclude-filter>的使用原因,为什么在applicationContext.xml中排除controller,而在spring-mvc.xml中incloud这个controller
- webApplication的理解以及对应的配置解读
- WebApplication和WebSite的区别
- WebSite与WebApplication的区别
- WebApplication编程模型的优点
- WebSite和WebApplication的区别
- WebService与WebApplication的区别
- WebService与WebApplication的区别
- WebService与WebApplication的区别
- 文件上传的方式以及对应的配置
- android颜色表 以及颜色对应的xml配置值
- 深入解读Quartz的原理(以及Spring配置)
- DJ WebApplication模板jQuery的DatePicker控件
- webApplication 與 web site 的區別
- sharepoint修改webapplication应用端口的语句
- WebSite 和 WebApplication的区别【转】
- WebApplication和WebSite网站的区别
- 首页对应的模板,以及对应的类
- 中国电信 对应的TPLink配置
- 使用glide图片加载框架将网络图片展示并在listview中
- leetcode_572. Subtree of Another Tree ? 待解决
- 《极客与团队》【PDF】下载
- 微信运动过气了吗?
- python学习之日志模块logging
- webApplication的理解以及对应的配置解读
- 「敏捷开发」适合什么样的团队?
- 抽象类 和 接口
- 使用logback写日志
- 利用matplotlib画sigmoid函数
- 当变化来临,PM的心态和节奏如何把握?
- RSA实例详解
- 问答专场 | 我是蝉游记创始人纯银V,你有什么想问我?
- Markdown系列(8)- Markdown编辑器和常见的富文本编辑器有什么区别