spring加载配置文件三办法
来源:互联网 发布:软件测试报告模板范文 编辑:程序博客网 时间:2024/04/30 03:32
总结一下: 据我目前所知的spring有三种方式来创建ApplicationContext.
1、把applicationContext.xml直接放在WEB-INF/classes下,spring会采用默认的加载方式
2、采用在web.xml中配置ContextLoaderListenera或ContextLoaderServlet指定加载路径方式。它们两个有着同样的功能,都实现在了org.springframework.web.context.ContextLoader类,都要定义contextConfigLocation参数。区别在于listener不能在Servlet 2.2兼容的容器中使用。自从Servelt 2.4规范,listener被要求在web应用启动后初始化。web.xml初始化的时候,listerner会检查contextConfigLocation参数。如果不存在的话,它将默认使用/WEB-INF/applicationContext.xml。如果它存在,它就会用预先定义的分隔符(逗号,分号和空格)分开分割字符串(<param-value></param-value),并将这些值作为应用上下文将要搜索的位置。
代码
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/daoContext.xml,
/WEB-INF/config/appContext1.xml,
/WEB-INF/config/appContext2.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 另一种是使用ContextLoaderServlet
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
-->
3 通过ClassPathXmlApplicationContext或XmlWebApplicationContext代码动态加载!
- spring加载配置文件三办法
- Spring加载配置文件的三种方式
- 加载spring配置文件的常用三种方法
- 加载Spring配置文件常用的三种方法
- 加载spring配置文件的常用三种方法
- 加载spring配置文件的常用三种方法
- Web应用中加载Spring配置文件的三种方法
- Spring Framework源码(三):IOC容器配置文件加载
- Spring加载配置文件和三种Bean实例化
- Spring配置文件加载外部配置文件
- spring配置文件加载
- spring多配置文件加载
- spring 加载配置文件
- Spring配置文件加载流程
- spring加载xml配置文件
- spring加载配置文件
- spring 配置文件加载方式
- spring配置文件加载流程
- 程序员想创业首先要突破自己三关
- plsql学习
- 什么是OSGI
- 一些好文章的链接
- RadioButtonList专题
- spring加载配置文件三办法
- linux 旧信号新计时器实例
- Vista
- PL/SQL DEVELOPER 基本用法详解(转)
- 重复提交解决方案
- gettext简介
- 在web客户端生成word文件
- Eclipse常用快捷键小结
- My God!--如此登陆校验码