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 ...
随机推荐
- kali linux之Audacity
常用音频隐写工具 安装: sudo apt install audacity 初次打开的界面 看波的宽度分辨长短音 比较细的就是短音,代表".",比较粗的就是长音,代表" ...
- Elasticsearch(9):使用Logstash-input-jdbc同步数据库中的数
1.数据同步方式 全量同步与增量同步 全量同步是指全部将数据同步到es,通常是刚建立es,第一次同步时使用.增量同步是指将后续的更新.插入记录同步到es. 2.常用的一些ES同步方法 1). elas ...
- Markdown入门简介
参考 http://sspai.com/25137 作者: Te_Lee 文章来源: 少数派 Markdown入门简介(使用工具Haroopad) 一.使用的工具----haroopad(http:/ ...
- angular4套用primeng样式
首先安装primeng cnpm install primeng --save 这样会在项目目录中增加node_modules\primeng目录 package.json文件增加了以下一行 &quo ...
- QuantLib 金融计算——基本组件之 DayCounter 类
目录 QuantLib 金融计算--基本组件之 DayCounter 类 DayCounter 对象的构造 一些常用的成员函数 如果未做特别说明,文中的程序都是 Python3 代码. QuantLi ...
- JavaScript DOM编程艺术 笔记(四)
DOM document object model(map) 家谱树---节点树 父 子 兄弟 元素节点 <div> 文本节点 内容 属性节点 value src getE ...
- 0、weka学习与使用
转载自:https://blog.csdn.net/u011067360/article/details/20844443 数据挖掘开源软件:WEKA基础教程 本文档部分来自于网络,随着自己的深入学习 ...
- JSONP-跨域读取数据
页面代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <tit ...
- python全栈开发学习_内容目录及链接
python全栈开发学习_day1_计算机五大组成部分及操作系统 python全栈开发学习_day2_语言种类及变量 python全栈开发_day3_数据类型,输入输出及运算符 python全栈开发_ ...
- rbac - 介绍
找到了上学期末压箱底的rbac组件,这里总结下. 介绍: rbac组件:一个基于角色的权限访问控制系统的组件. 目录: