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 ...
随机推荐
- 前端传给后端的数据类型为ImmutableMultiDict 咋办
https://segmentfault.com/q/1010000002802028 偷得人家的答案 以下是解决办法:::: -------------------------------- ...
- PHP 访问链接的3种方式
对于php访问url的方法比价多,对于一些防护比较低的网站,可以轻易的实现刷网站浏览量的可能 1.fopen方式 function access_url($url) { if ($url=='') r ...
- [CSS3] :nth-child的用法
:nth-child(2)选取第几个标签,“2可以是你想要的数字” .demo01 li:nth-child(2){background:#090} :nth-child(n+4)选取大于等于4标签, ...
- TPS和QPS定义以及影响TPS的因素
一.TPS:Transactions Per Second(每秒传输的事物处理个数),即服务器每秒处理的事务数.TPS包括一条消息入和一条消息出,加上一次用户数据库访问.(业务TPS = CAPS × ...
- lnmp环境搭建错误集合
错误1: 页面显示:No input file specified nginx错误日志:FastCGI sent in stderr: "PHP message: PHP Warning: ...
- leetcode-77-组合
题目描述: 给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合. 示例: 输入: n = 4, k = 2 输出: [ [2,4], [3,4], [2,3], [1,2], ...
- 架构师养成记--25.linux用户管理
用户管理配置文件用户信息文件:/etc/passwd密码文件:/etc/shadow用户配置文件:/etc/login.defs /etc/default/useradd新用户信息文件:/etc/sk ...
- 高斯分布(Gaussian Distribution)的概率密度函数(probability density function)
高斯分布(Gaussian Distribution)的概率密度函数(probability density function) 对应于numpy中: numpy.random.normal(loc= ...
- django文章收藏
http://www.cnblogs.com/suoning/p/5818869.html
- (C/C++) FILE 讀寫檔案操作
在C/C++ 讀寫檔案操作比較常見應該是利用 FILE.ifstream.ofstream 在這篇筆記裡頭記錄 FILE.fstream 使用方法及操作 #include <iostream&g ...