spring 加载流程走向
2016-04-01 16:42
471 查看
spring提供了一个ContextLoaderListener类 它会在web启动时加载然后去WEB-INF下寻找applicationContext.xml文件 并根据它来创建spring容器。
一个项目中如果需要使用spring 还需要在web。xml中如下配置:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
如果web.xml想加载多个文件应该如下配置:
<context-param>
<param-name>ContextConfigLocation</param-name>
<param-value>/WEB-INF/dao.xml,/WEB-INF/applicationContext.xml</param-value>
<-context-param>
在ContextLoaderListener加载时它会去查找一个名为ContextConfigLocation的参数所以这是固定的使用此种方法是web2.3之后的 之前的它不支持 我们可以采用另一种做法
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderListener</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
相当于使用<load-on-startup>1</load-on-startup>方式来加载这个的值越小表示越早加载
一个项目中如果需要使用spring 还需要在web。xml中如下配置:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
如果web.xml想加载多个文件应该如下配置:
<context-param>
<param-name>ContextConfigLocation</param-name>
<param-value>/WEB-INF/dao.xml,/WEB-INF/applicationContext.xml</param-value>
<-context-param>
在ContextLoaderListener加载时它会去查找一个名为ContextConfigLocation的参数所以这是固定的使用此种方法是web2.3之后的 之前的它不支持 我们可以采用另一种做法
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderListener</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
相当于使用<load-on-startup>1</load-on-startup>方式来加载这个的值越小表示越早加载
相关文章推荐
- Java核心知识点-多线程同步锁
- Java反序列化
- Web加载Spring的过程
- Java二维数组
- org.springframework.dao.DuplicateKeyException:
- FreeMarker应用一例——生成Java代码
- Java中overload和override的区别
- Spring MVC系列(四)之session处理---@SessionAttributes
- Java读取html页面以文件流方式输出显示在页面
- webSocket 案例 使用spring4.0.0
- Spring 的事务,分布式事务。
- 小白的成长之路(1)--安装JDK
- ServletContextListener 启动SPRING加载数据到缓存的应用
- 初探springMVC
- (转)见证spring jdbc
- Java单链表基本操作(九)--交换相邻节点对的值
- 解析spring的IOC、AOP?
- Spring构造器注入、set注入和注解注入
- 关于java.util.Properties读取中文乱码的正确解决方案(不要再用native2ascii.exe了)
- Spring 事务学习笔记(1):事务的基本知识