1.在ApplicationContext容器中,我们以常用的FileSystemXmlApplicationContext实现为例来说明ApplicationContext容器的设计原理

2.在FileSystemXmlApplicationContext的设计中,我们看到ApplicationContext应用上下文的主要功能已经在FileSystemXmlApplicationContext的基类AbstractXmlApplication中实现了,在FileSystemXmlApplicationContext中,作为一个具体的应用上下文,只需要实现和它自身设计相关两个功能

3.一个功能是,如果应用直接使用FileSystemXmlApplicationContext,对于实例化这个应用上下文支持同时启动IoC容器的refresh()过程。这在FileSystemXmlApplicationContext的代码实现中可以看到,代码如下:

 1 /**
 2      * Create a new FileSystemXmlApplicationContext with the given parent,
 3      * loading the definitions from the given XML files.
 4      * @param configLocations array of file paths
 5      * @param refresh whether to automatically refresh the context,
 6      * loading all bean definitions and creating all singletons.
 7      * Alternatively, call refresh manually after further configuring the context.
 8      * @param parent the parent context
 9      * @throws BeansException if context creation failed
10      * @see #refresh()
11      */
12     public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent)
13             throws BeansException {
14
15         super(parent);
16         setConfigLocations(configLocations);
17         if (refresh) {
18             refresh();
19         }
20     }

FileSystemXmlApplicationContext(String[] configLocations,boolean,ApplicationContext)

4.这个refresh()过程会牵涉IoC容器启动一系列复杂操作,同时,对于不同的容器实现,这些操作都是类似的,因此在基类中将它们封装好。所以,我们在FileSystemXmlApplicationContext的设计中看到的只是一个简单的调用。

5.另一功能是与FileSystemXmlApplicationContext设计具体相关的功能,这部分与怎样从文件系统加载XML的Bean定义资源有关。

6.通过这个实现,可以在文件系统中读取以XML形式存在的BeanDefinition做准备,因为不同的应用上下文实现对应着不同的读取BeanDefinition的方式,在FileSystemXmlApplicationContext中的实现代码如下:

 1 /**
 2      * Create a new FileSystemXmlApplicationContext with the given parent,
 3      * loading the definitions from the given XML files.
 4      * @param configLocations array of file paths
 5      * @param refresh whether to automatically refresh the context,
 6      * loading all bean definitions and creating all singletons.
 7      * Alternatively, call refresh manually after further configuring the context.
 8      * @param parent the parent context
 9      * @throws BeansException if context creation failed
10      * @see #refresh()
11      */
12     public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent)
13             throws BeansException {
14
15         super(parent);
16         setConfigLocations(configLocations);
17         if (refresh) {
18             refresh();
19         }
20     }

getResourceByPath

可以看到,调用这个方法,可以得到FileSystemResource的资源定位。

转载于:https://www.cnblogs.com/duffy/p/3953712.html

ApplicationContext容器的设计原理相关推荐

  1. BeanFactory容器的设计原理

    BeanFactory接口提供了使用IOC容器的规范.在这个基础上,Spring还提供了符合这个IOC容器借口了的一系列容器的实现供开发人员使用.先以XmlBeanFactory的实现为例来 说明简单 ...

  2. Spring IoC(一)IoC容器的设计与实现:BeanFactory与ApplicationContext

    在写BeanFactory与ApplicationContext 之前,我想先简单聊一聊Spring IoC 容器,希望能给大家一个参考.如果你对这反面的知识比较了解,可以直接跳过. (一)Sprin ...

  3. 深入剖析Spring架构与设计原理(一)

    深入剖析Spring架构与设计原理(一) 1. IOC的基础 IOC/AOP是Spring的基础, 是Spring平台实现的核心部分. 虽然,我们一开始大多只是在这个层面上,做一些配置和外部特性的使用 ...

  4. Spring Cloud- Ribbon设计原理

    Ribbon 是netflix 公司开源的基于客户端的负载均衡组件,是Spring Cloud大家庭中非常重要的一个模块:Ribbon应该也是整个大家庭中相对而言比较复杂的模块,直接影响到服务调度的质 ...

  5. 配置中心Apollo的设计原理

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试文章 来源:https://urlify.cn/eIBZne 前言 Ap ...

  6. 深入解析Spring架构与设计原理-AOP

    2019独角兽企业重金招聘Python工程师标准>>> 关于AOP的个人理解 AOP联盟定义的AOP体系结构把与AOP相关的概念大致分为了由高到低.从使用到实现的三个层次.关于这个体 ...

  7. java B2B2C Springcloud电子商城系统-Ribbon设计原理

    Ribbon 是netflix 公司开源的基于客户端的负载均衡组件,是Spring Cloud大家庭中非常重要的一个模块:Ribbon应该也是整个大家庭中相对而言比较复杂的模块,直接影响到服务调度的质 ...

  8. quartz 分布式_后端必备分布式技术之-调度系统Quartz设计原理

    调度系统作为分布式系统技术中重要的一环,了解其技术原理必不可少,不同系统内部采用的调度系统叫法不一样,但大致功能都类似,而Quartz作为经典的开源企业级调度系统,怎么能不研究一下呢? 为什么要学习q ...

  9. spring技术内幕——深入解析spring架构与设计原理

    林纳斯·托瓦兹(Linus Torvalds)说:"我从心底认为,优秀的程序员与平庸的程序员之间的区别,是在于认为自己的代码重要还是数据结构更加重要.平庸的程序员眼里只有代码,优秀的程序员则 ...

最新文章

  1. 张亚勤谈数字化3.0:由物理与生物世界的数字化构成 | WIC
  2. 2021年需要学习Python的自动化测试框架有哪些?你知道吗?
  3. WCF 改成 restful api
  4. nagios 3.2安装详解(一)
  5. 源码篇:Python 实战案例----银行系统
  6. 中邮智递通过数加和datav将系统和服务迁移到大数据平台
  7. 新版知识付费系统付费阅读小程序源码知识付费平台
  8. structs 1.x 学习
  9. SpringBoot接收数组参数
  10. 最小二乘方法和RANSAC的改进算法PROSAC和LMEDS
  11. 行列转换的SQL语句
  12. Springboot课设旅游推荐系统
  13. python 查询oracle数据库返回具体字段名
  14. HTML 标签全写及描述
  15. 常见C++开源网站项目
  16. 商务签证之结局:面试
  17. Excel中使用正则表达式的方法
  18. 专业jpg转pdf软件
  19. joan sola_Joan Touzet在CouchDB和Apache方式上
  20. Android Google Maps教程

热门文章

  1. 前端技术周刊 2019-01-21:跨端开发的三条路线
  2. Ignite中的机器学习介绍
  3. Linux中断 - tasklet
  4. 网页制作小技巧:dl dt dd标签用法
  5. Flex 布局教程:语法
  6. jQuery属性筛选选择器
  7. CentOS 6.3 下用ntfs-3g挂载Windows NTFS分区
  8. 周鸿祎:在360新员工入职培训上的讲话
  9. 读书笔记《集体智慧编程》Chapter 5 : Optimization
  10. 关于Exchange管理控制台报“您的权限不足,无法此查看数据”的解决办法