Spring 创建 IOC 容器时加载配置文件的几种方式
一、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 容器时加载配置文件的几种方式的更多相关文章
- SpringBoot加载配置文件的几种方式
首先回忆一下在没有使用SpringBoot之前也就是传统的spring项目中是如何读取配置文件,通过I/O流读取指定路径的配置文件,然后再去获取指定的配置信息. 传统项目读取配置方式 读取xml配置文 ...
- mybatis 加载配置文件的两种方式
package com.atguigu.day03_mybaits.test; import java.io.IOException;import java.io.InputStream;import ...
- java加载配置文件的三种方式
比如我们要加载db.properties文件 如图: 比如我们要加载source目录下的db.properties文件.就有以下几种方式 第一种是文件io流: public static void l ...
- Spring源码剖析2:Spring IOC容器的加载过程
spring ioc 容器的加载流程 1.目标:熟练使用spring,并分析其源码,了解其中的思想.这篇主要介绍spring ioc 容器的加载 2.前提条件:会使用debug 3.源码分析方法:In ...
- Spring源码剖析3:Spring IOC容器的加载过程
本文转自五月的仓颉 https://www.cnblogs.com/xrq730 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https ...
- Spring ——获取IOC容器时,构造方法、set方法、类方法执行顺序
1,首先,我们在ApplicationContext.xml中会写下下面类的标示: <bean id="helloword" class="com.xt.frist ...
- [Android] Android ViewPager 中加载 Fragment的两种方式 方式(二)
接上文: https://www.cnblogs.com/wukong1688/p/10693338.html Android ViewPager 中加载 Fragmenet的两种方式 方式(一) 二 ...
- Vue加载组件、动态加载组件的几种方式
https://cn.vuejs.org/v2/guide/components.html https://cn.vuejs.org/v2/guide/components-dynamic-async ...
- JavaScript判断图片是否加载完成的三种方式
JavaScript判断图片是否加载完成的三种方式 有时需要获取图片的尺寸,这需要在图片加载完成以后才可以.有三种方式实现,下面一一介绍. 一.load事件 1 2 3 4 5 6 7 8 9 10 ...
随机推荐
- InnoDB: The innodb_system data file 'ibdata1' must be writable错误
重新安装percona5.7过程中,启动mysql服务总是报如下的错误 --10T02::.781070Z [ERROR] InnoDB: The innodb_system data file 'i ...
- javascript高逼格代码实现数组去重,JSON深度拷贝,匿名函数自执行,数字取整等
1.如何装逼用代码骂别人傻逼 (!(~+[])+{})[--[~+""][+[]]*[~+[]] + ~~!+[]]+({}+[])[[~!+[]]*~+[]] 2.如何优雅的用代 ...
- python3+requests:post请求四种传送正文方式(详解)
前言:post请求我在python接口自动化2-发送post请求详解(二)已经讲过一部分了,主要是发送一些较长的数据,还有就是数据比较安全等,可以参考Get,Post请求方式经典详解进行学习一下. 我 ...
- drools入门示例
Drools是一个基于java的规则引擎,开源的,可以将复杂多变的规则从硬编码中解放出来,以规则脚本的形式存放在文件中,使得规则的变更不需要修正代码重启机器就可以立即在线上环境生效.随着互联网金融的兴 ...
- 分析解决Java运行时异常
1 ,基础知识 http://my.oschina.net/u/140462/blog/421128 JVM运行时内存结构 2 ,相关命令 http ...
- 45.oracle表类型、数据拆分、表分区
不要做一些没有意义的事情,就比如说你要离职并不打算吃回头草,离职理由中完全没有必要说明“领导的水平太渣,人品太差”此类的原因,而是“个人原因”,当然实在不批准辞职另说. oracle表类型 表的类型分 ...
- CodeForces - 556C-Case of Matryoshkas(思维)
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at ...
- 如何对react进行性能优化
React本身就非常关注性能,其提供的虚拟DOM搭配上DIff算法,实现对DOM操作最小粒度的改变也是非常高效的,然而其组件的渲染机制,也决定了在对组件更新时还可以进行更细致的优化. react组件 ...
- @SafeVarargs注解
被@SafeVarargs注解标注的方法必须是由static或者final修饰的方法. 使用泛型的变长参数方法产生编译器警告的示例: public static <T> T useVara ...
- elixir二进制模式匹配
for << << b1::size(2), b2::size(3), b3::size(3) >> <- "hello" >> ...