Spring技术内幕之IOC容器的实现(02)-BeanDefinition的Resource定位
来源:互联网 发布:淘宝双11优惠 编辑:程序博客网 时间:2024/05/16 15:45
Spring 为可以更方面的从不同的地方读取Resource,从而为我们提供了一系列加载不同的Resource的读取器的实现,
例如:
FileSystemXmlApplicationContext可以从文件系统载入Resource
ClassPathXmlApplicationContext可以从类路径载入Resource
XmlWebApplicationContext可以在web容器中载入Resource
下面我们以FileSystemXmlApplicationContext为例,来理解BeanDefinition是如何Resource定位的,下面是FileSystemXmlApplicationContext的继承体系图:
package com.bjhy.platform.criminal.search.system.test;import org.springframework.beans.BeansException;import org.springframework.context.ApplicationContext;import org.springframework.context.support.AbstractXmlApplicationContext;import org.springframework.core.io.FileSystemResource;import org.springframework.core.io.Resource;/** * 从文件系统中载入Resource * */public class FileSystemXmlApplicationContext extends AbstractXmlApplicationContext {/** * 无参数的构造方法 */public FileSystemXmlApplicationContext() {} /** * @param parent ApplicationContext上下文对象 */public FileSystemXmlApplicationContext(ApplicationContext parent) {super(parent);} /** * @param configLocation BeanDefinition所在的文件路径 * @throws BeansException BeansException异常 */public FileSystemXmlApplicationContext(String configLocation) throws BeansException {this(new String[] {configLocation}, true, null);} /** * @param configLocation 允许包含多个BeanDefinition所在的文件路径 * @throws BeansException BeansException异常 */public FileSystemXmlApplicationContext(String... configLocations) throws BeansException {this(configLocations, true, null);} /** * 这个构造函数允许configLocations包含多个BeanDefinition的文件路径,同时还允许指定自己的双亲IOC容器 * @param configLocations 允许包含多个BeanDefinition所在的文件路径 * @param parent ApplicationContext * @throws BeansException */public FileSystemXmlApplicationContext(String[] configLocations, ApplicationContext parent) throws BeansException {this(configLocations, true, parent);}public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh) throws BeansException {this(configLocations, refresh, null);} /** * 在对象的初始化过程中,调用refresh函数载入BeanDefinition * @param configLocations 允许包含多个BeanDefinition所在的文件路径 * @param refresh 是否启动初始化IOC容器 * @param parent ApplicationContext * @throws BeansException * */public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent)throws BeansException {super(parent);setConfigLocations(configLocations);if (refresh) {refresh();//启动BeanDefinition资源定位过程}} /** * 这是应用于文件系统中的Resource实现,通过构造一个FileSystemResource来得到一个在文件系统定位的BeanDefinition, * 这个getResourceByPath是在BeanDefinition的loadBeanDefinition中被调用的 * loadBeanDefinition采用模板模式,具体的实现实际上由各个子类完成 */@Overrideprotected Resource getResourceByPath(String path) {if (path != null && path.startsWith("/")) {path = path.substring(1);}return new FileSystemResource(path);}}
<getResourceByPath的调用过程>:
FileSystemXmlApplicationContext ----调用refreshBeanFactory--->AbstractRefreshableApplicationContext -------调用getResourceByPath-->FileSystemResource----->最终返回FileSystemResource
0 0
- Spring技术内幕之IOC容器的实现(02)-BeanDefinition的Resource定位
- spring 技术内幕--IOC初始化之BeanDefinition的在IOC容器中的注册
- 【Spring源码--IOC容器的实现】(二)BeanDefinition的Resource定位
- spring 技术内幕--IOC初始化过程深入之BeanDefinition的定位
- spring技术内幕笔记:IoC容器的初始化过程(3)- BeanDefinition的注册
- spring技术内幕之IoC容器的实现
- spring技术内幕笔记:IoC容器初始化过程(2)- BeanDefinition的载入
- Spring技术内幕之IOC容器的实现(01)-IOC容器初始化过程
- spring 技术内幕--IOC初始化过程深入之BeanDefinition的载入和解析1
- Spring技术内幕笔记 -- IoC容器的实现
- 《Spring技术内幕》笔记-第二章 IoC容器的实现
- Spring技术内幕——IoC容器的实现
- Spring技术核心内幕 读书笔记--IOC容器的实现小结
- 深探spring系列-----ioc初始化(1)BeanDefinition的Resource定位
- spring技术内幕笔记:IoC容器初始化过程(1)- Resource定位
- 5-spring源码3.2.18解读+spring技术内幕(关于BeanDefinition的定位)
- Spring技术内幕2Spring Framework的核心:IoC容器的实现
- Spring技术内幕——Spring Framework的IOC容器实现(一)
- 读写Excel -- ExcelToolUtil
- 【Spring学习】IoC与DI
- 《Linux4.0设备驱动开发详解》笔记--第七章:Linux设备中的并发控制
- 1分钟快速生成用于网页内容提取的xslt
- 部分和问题-dfs穷举
- Spring技术内幕之IOC容器的实现(02)-BeanDefinition的Resource定位
- 设计模式之建造者模式
- python 爬虫 精华
- 怎样快速创建淘宝店铺app,手机店铺app?
- mysql varchar 类型的等于
- MySQL数据库的修复
- android上的JAVA8:使用retrolambda
- 阀值与阈值的差别
- C++中常见类型转换