Spring 创建 IOC 容器 ClassPathXmlApplicationContext 类
一、ClassPathXmlApplicationContext 类路径加载
1. 使用 classpath 路径,classpath 前缀加不加都可以。
ApplicationContext act = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
// 使用ClassPath路径可以不加前缀
ApplicationContext act = new ClassPathXmlApplicationContext("applicationContext.xml");
2. 使用磁盘绝对路径,必须要加前缀file。
ApplicationContext act = new ClassPathXmlApplicationContext("file:F:/stud/src/main/webapp/WEB-INF/applicationContext.xml");
3. 当有多个配置文件时
ApplicationContext act = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","spring.xml"});
4. 使用通配符
ApplicationContext act = new ClassPathXmlApplicationContext("application-*.xml");
二、FileSystemXmlApplicationContext 文件系统加载
该类参数抓取规则与 ClassPathXmlApplicationContext 相比,多了一项:
1. 使用项目的根目录
ApplicationContext act = new FileSystemXmlApplicationContext("src/main/resources/applicationContext.xml");
相同的两种抓取规则:
2. 也可以使用classpath路径,但不同的是:必须有前缀
ApplicationContext act = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
3. 使用磁盘的绝对路径,但不同的是:前缀可以不加。
ApplicationContext act = new FileSystemXmlApplicationContext("file:F:/stud/kaptcha/src/main/webapp/WEB-INF/applicationContext.xml");
// 使用磁盘绝对路径可以不加前缀
ApplicationContext act = new FileSystemXmlApplicationContext("F:/stud/kaptcha/src/main/webapp/WEB-INF/applicationContext.xml");
Spring 创建 IOC 容器 ClassPathXmlApplicationContext 类的更多相关文章
- Java进阶知识16 Spring创建IOC容器的两种方式
1.直接得到 IOC 容器对象 ApplicationContext applicationContext = new ClassPathXmlApplicationContext("app ...
- Spring 创建 IOC 容器时加载配置文件的几种方式
一.ClassPathXmlApplicationContext 类路径加载 1. 使用 classpath 路径,classpath 前缀加不加都可以. ApplicationContext act ...
- spring学习笔记三:Component注解(把POJO类实例化到spring的IOC容器中)
Component注解:把普通的POJO 类实例化到spring的IOC容器中,就是定义成<bean id="" class=""> 项目目录树: ...
- SpringMVC系列(十五)Spring MVC与Spring整合时实例被创建两次的解决方案以及Spring 的 IOC 容器和 SpringMVC 的 IOC 容器的关系
一.Spring MVC与Spring整合时实例被创建两次的解决方案 1.问题产生的原因 Spring MVC的配置文件和Spring的配置文件里面都使用了扫描注解<context:compon ...
- spring框架--IOC容器,依赖注入
思考: 1. 对象创建创建能否写死? 2. 对象创建细节 对象数量 action 多个 [维护成员变量] service 一个 [不需要维护公共变量] dao 一个 [不需要维护 ...
- spring之IOC容器创建对象
1.术语了解 1.1组件/框架设计 侵入式设计 引入了框架,对现有的类的结构有影响:即需要实现或继承某些特定类. 例如: Struts框架非侵入式设计 引入了框架,对现有的类结构没有影响. 例如:Hi ...
- Spring ——获取IOC容器时,构造方法、set方法、类方法执行顺序
1,首先,我们在ApplicationContext.xml中会写下下面类的标示: <bean id="helloword" class="com.xt.frist ...
- Spring框架IOC容器和AOP解析
主要分析点: 一.Spring开源框架的简介 二.Spring下IOC容器和DI(依赖注入Dependency injection) 三.Spring下面向切面编程(AOP)和事务管理配置 一.S ...
- Spring之IOC容器加载初始化的方式
引言 我们知道IOC容器时Spring的核心,可是如果我们要依赖IOC容器对我们的Bean进行管理,那么我们就需要告诉IOC容易他需要管理哪些Bean而且这些Bean有什么要求,这些工作就是通过通过配 ...
随机推荐
- dubbo学习笔记
一.zookeeper在Dubbo中扮演角色 流程:1.服务提供者启动时向/dubbo/com.foo.BarService/providers目录下写入URL2.服务消费者启动时订阅/dubbo/c ...
- Scrapy框架安装配置小结
Windows 平台: 系统是 Win7 Python 2.7.7版本 官网文档:http://doc.scrapy.org/en/latest/intro/install.html 1.安装Pyt ...
- (三)Python在windows上安装
1.安装2.7--进入python官网(网址百度)下载python2.7 和python3.6(很小,2个程序后缀不一样?)2.安装到c:\python----next----advanced不动-- ...
- CentOS 7安装redis及php扩展
安装remi源 # wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm # rpm -Uvh remi-release-7 ...
- mongodb tip-2
1.or 查询的格式: var condition = {$or:[{field:1},{field:2}]} 2.字符串存储日期也可以用$gt $gte $lt $lte 直接比较 var cond ...
- input的placeholder字体大小无法修改?
链接如下 其实chrome是有这个东西的,那就是shadow DOM. 什么是Shadow-Dom?Shadow DOM是指浏览器的一种能力,它允许在文档(document)渲染时插入一棵DOM元素子 ...
- DOM学习笔记--入门1
HTML DOM 是关于如何获取.修改.添加或删除 HTML 元素的标准. 首先节点有很多种,不仅仅HTML元素是节点,尤其 要注意文本节点的存在. 根据 W3C 的 HTML DOM 标准,HTML ...
- 【Time系列五】个性时钟与秒表升级版
从昨天到现在,一直在研究这个看起来超级简单的时钟.界面非常简洁大方. 虽然是简单,可是这个对齐的问题还是把我整得一塌糊涂.谁叫作者不解释清楚的. 参考:http://bbs.fishc.com/thr ...
- U3D音频系统
一.基本信息 1.支持的声音格式 WAV OGG MP3 AIFF MOD S3M xm IT 导入以后,unity会选择的压缩方式: WAV:无损,音质好,文件大,适用于较短文件 OGG.MP ...
- linux重要命令
echo echo命令用于在终端显示字符串或输出变量提取后的值,格式为:"echo [字符串 | $变量]". 将指定字符串输出到终端屏幕: [root@linuxprobe ~] ...