您的位置:首页 > 编程语言 > Java开发

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>方式来加载这个的值越小表示越早加载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: