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 ...
随机推荐
- [Objective-C语言教程]内存管理(36)
内存管理是任何编程语言中最重要的过程之一.它是在需要时分配对象的内存并在不再需要时取消分配的过程. 管理对象内存是一个性能问题; 如果应用程序不释放不需要的对象,则应用程序会因内存占用增加并且性能受损 ...
- 使用java执行ffmpeg命令进行推流操作
视频网站中提供的在线视频播放功能,播放的都是FLV格式的文件,它是Flash动画文件,可通过Flash制作的播放器来播放该文件.项目中用制作的player.swf播放器. 多媒体视频处理工具FFmpe ...
- day06 --class --home
# -*- coding: utf-8 -*-# @Time : 2018/12/26 20:29# @Author : Endless-cloud# @Site : # @File : day 06 ...
- Oracle的常用修改表及字段的语句
单行注释:-- 多行注释:/* */ Oracle中修改表结构 增加字段 ALTER TABLE table_name ADD column_name data_type; 删除字段 ...
- leetcode-733-Flood Fill
题目描述: An image is represented by a 2-D array of integers, each integer representing the pixel value ...
- 丢用lamp手动安装apache php mysql
Centos7环境下. 使用lamp环境无法正常显示出thinkphp站点的内容,一气之下,选择手动安装 第一步: 安装apache php 和php连接数据库的工具php-mysql [root@ ...
- Mondrian系列
1.Mondrian Schema Workbench 概念及常用参数 2.Schema Workbench 启动慢解决办法 3.自己写的第一个Schema文件 4.维度-退化维度 5.维度-共享维度 ...
- 【算法笔记】A1039 Course List for Student
https://pintia.cn/problem-sets/994805342720868352/problems/994805447855292416 题意: 有N个学生,K节课.给出选择每门课的 ...
- 【性能测试】:LR插入mysql数据库数据,脚本参数化问题
一,今天准备脚本做mysql数据库的铺地数据,脚本内容不赘述,在批量执行insert语句时候,出现一个问题: // sprintf(chQuery, "insert into table ( ...
- c#StreamWriter,StreamReader类(主要用于文本文件访问)
1.为什么要使用StreamReader或者StreamWriter 如果对文本文件需要读取一部分显示一部分则使用FileStream会有问题,因为可能FileStream会在读取的时候把一个汉字的字 ...