ApplicationContext容器的设计原理
1.在ApplicationContext容器中,我们以常用的FileSystemXmlApplicationContext的实现为例来说明ApplicationContext容器的设计原理。
2.在FileSystemXmlApplicationContext的设计中,我们看到ApplicationContext应用上下文的主要功能已经在FileSystemXmlApplicationContext的基类AbstractXmlApplication中实现了,在FileSystemXmlApplicationContext中,作为一个具体的应用上下文,只需要实现和它自身设计相关的两个功能。
3.一个功能是,如果应用直接使用FileSystemXmlApplicationContext,对于实例化这个应用上下文的支持,同时启动IoC容器的refresh()过程。这在FileSystemXmlApplicationContext的代码实现中可以看到,代码如下:
/**
* Create a new FileSystemXmlApplicationContext with the given parent,
* loading the definitions from the given XML files.
* @param configLocations array of file paths
* @param refresh whether to automatically refresh the context,
* loading all bean definitions and creating all singletons.
* Alternatively, call refresh manually after further configuring the context.
* @param parent the parent context
* @throws BeansException if context creation failed
* @see #refresh()
*/
public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent)
throws BeansException { super(parent);
setConfigLocations(configLocations);
if (refresh) {
refresh();
}
}
FileSystemXmlApplicationContext(String[] configLocations,boolean,ApplicationContext)
4.这个refresh()过程会牵涉IoC容器启动的一系列复杂操作,同时,对于不同的容器实现,这些操作都是类似的,因此在基类中将它们封装好。所以,我们在FileSystemXmlApplicationContext的设计中看到的只是一个简单的调用。
5.另一功能是与FileSystemXmlApplicationContext设计具体相关的功能,这部分与怎样从文件系统中加载XML的Bean定义资源有关。
6.通过这个实现,可以在文件系统中读取以XML形式存在的BeanDefinition做准备,因为不同的应用上下文实现对应着不同的读取BeanDefinition的方式,在FileSystemXmlApplicationContext中的实现代码如下:
/**
* Create a new FileSystemXmlApplicationContext with the given parent,
* loading the definitions from the given XML files.
* @param configLocations array of file paths
* @param refresh whether to automatically refresh the context,
* loading all bean definitions and creating all singletons.
* Alternatively, call refresh manually after further configuring the context.
* @param parent the parent context
* @throws BeansException if context creation failed
* @see #refresh()
*/
public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent)
throws BeansException { super(parent);
setConfigLocations(configLocations);
if (refresh) {
refresh();
}
}
getResourceByPath
可以看到,调用这个方法,可以得到FileSystemResource的资源定位。
ApplicationContext容器的设计原理的更多相关文章
- BeanFactory容器的设计原理
XmlBeanFactory设计的类继承关系 1.BeanFactory接口提供了使用IoC容器的规范.在这个基础上,Spring还提供了符合这个IoC容器接口的一系列容器的实现供开发人员使用. 2. ...
- Spring源码解析-ioc容器的设计
Spring源码解析-ioc容器的设计 1 IoC容器系列的设计:BeanFactory和ApplicatioContext 在Spring容器中,主要分为两个主要的容器系列,一个是实现BeanFac ...
- Spring技术内幕——深入解析Spring架构与设计原理(一)IOC实现原理
IOC的基础 下面我们从IOC/AOP开始,它们是Spring平台实现的核心部分:虽然,我们一开始大多只是在这个层面上,做一些配置和外部特性的使用工作,但对这两个核心模块工作原理和运作机制的理解,对深 ...
- Spring IOC设计原理解析:本文乃学习整理参考而来
Spring IOC设计原理解析:本文乃学习整理参考而来 一. 什么是Ioc/DI? 二. Spring IOC体系结构 (1) BeanFactory (2) BeanDefinition 三. I ...
- SpringMVC 原理 - 设计原理、启动过程、请求处理详细解读
SpringMVC 原理 - 设计原理.启动过程.请求处理详细解读 目录 一. 设计原理 二. 启动过程 三. 请求处理 一. 设计原理 Servlet 规范 SpringMVC 是基于 Servle ...
- Spring IOC容器的实现原理
1 概述 1.1 依赖反转模式 在Java中,一个复杂的功能一般都需要由两个或者两个以上的类通过彼此合作来实现业务逻辑的,这使得每个对象都需要与其合作的对象的引用.如果这个获取依赖对象的过程需要自己去 ...
- 【转】Spring学习---Spring IoC容器的核心原理
[原文] Spring的两个核心概念:IoC和AOP的雏形,Spring的历史变迁和如今的生态帝国. IoC和DI的基本概念 IoC(控制反转,英文含义:Inverse of Control)是Spr ...
- 高性能页面加载技术--BigPipe设计原理及Java简单实现
1.技术背景 动态web网站的历史可以追溯到万维网初期,相比于静态网站,动态网站提供了强大的可交互功能.经过几十年的发展,动态网站在互动性和页面显示效果上有了很大的提升,但是对于网站动态网站的整体页面 ...
- sping IOC的设计原理和高级特性
1. IOC 是Spring的内核,字面意思是控制反转,并提出了DI依赖注入的概念. 2.Spirng 容器的设计中,一个是实现BeanFactory 接口的简单饿汉容器,另外一个是比较高级的Appl ...
随机推荐
- Android 数据库打包随APK发布
有些时候我们的软件用到SQLite数据库,这个时候怎么把一个做好的数据库打包进我们的APK呢,其实很简单,就是把我们的数据库文件放到我们的手机里,所以不必局限在哪个地方写这个代码,在第一次创建数据库的 ...
- 在android market发布个人免费应用的步骤
写了一段时间的android应用了,只是在自己手机上面安装. 上周申请了android developer,需要一次性25美元的程序开发注册费用.费用需要用google checkout,所以还要先申 ...
- 你可能不知道的SQL问题
1. 如下是sql语句和结果, SELECT count(*) AS total FROM orders; +-------+ | total | +-------+ | 150 | +------ ...
- MYSQL: Handler_read_%参数说明
环境: 表t_feed_idx(user_id bigint, feed_id bigint, KEY (`user_id`,`feed_id`)) engine=innodb;表t_feed_i ...
- MYSQL 博客
DavidYang的博客 - CSDN.NET DimitriK's (dim) Weblog Xaprb · Stay Curious! 飞鸿无痕的博客 - ChinaUnix博客 何登成的技术博客 ...
- php与mysql的链接到底用mysql 还是mysqli,pdo
参考:http://php.net/manual/en/mysqlinfo.api.choosing.php
- java发送邮件 实现编辑html代码
这个例子相当的简单,一看就懂( 此例仅支持163发送163及qq邮箱) 首先要导入两个必须jar包:mail-1.4.4.jar 和 commons-email-1.2.jar这两个jar包是我用的 ...
- Maven-编译打包
1. 打包时忽略测试阶段 mvn clean mvn package -DskipTests
- Free download SKP900 update tool & activation tool
One of the SKP900 key programmer user failed to get the SKP900 upgraded and add free tokens online u ...
- [转]Android中内存占用的含义:(VSS,PSS,RSS,USS)
Android中内存占用的含义:(VSS,PSS,RSS,USS) 作者: andforce 分类: 安卓系统 发布时间: 2013-09-07 00:03 ė1,915 浏览数 6没有评论 在eng ...