前言

以前自己学习和实习的时候多次用过spring框架。对于我这种菜鸟来说,Spring给我的第一印象是好学,太TM好学了(抱歉没忍住脏话),跟着开发组熟悉几天就可以开始写代码,自我感觉代码敲得飞起~(苦笑),随着学习的深入,才发现自己坐井观天,还有太多的东西要学。现在决定沉下心来好好的找找自己的短板,本系列文章不会系统的介绍Spring的知识。首先明确定位,本系列的博客是小白文,我也是个学习者,可能很多东西大家看了会觉so easy,但适合自己的对我来说就是最好的,也记录成长的一个过程。

说明,如果文章借鉴一些前辈们的辛苦成果,会在文章最后标明。如有侵权问题或者不满意的地方请留言,我会第一时间修改。

1 ApplicationContext

API介绍如下:

public interface ApplicationContext
extends EnvironmentCapable, ListableBeanFactory, HierarchicalBeanFactory, MessageSource, ApplicationEventPublisher, ResourcePatternResolver Central interface to provide configuration for an application. This is read-only while the application is running, but may be reloaded if the implementation supports this. An ApplicationContext provides: Bean factory methods for accessing application components. Inherited from ListableBeanFactory.
The ability to load file resources in a generic fashion. Inherited from the ResourceLoader interface.
The ability to publish events to registered listeners. Inherited from the ApplicationEventPublisher interface.
The ability to resolve messages, supporting internationalization. Inherited from the MessageSource interface.
Inheritance from a parent context. Definitions in a descendant context will always take priority. This means, for example, that a single parent context can be used by an entire web application, while each servlet has its own child context that is independent of that of any other servlet. In addition to standard BeanFactory lifecycle capabilities, ApplicationContext implementations detect and invoke ApplicationContextAware beans as well as ResourceLoaderAware, ApplicationEventPublisherAware and MessageSourceAware beans.

很好理解,ApplicationContext很重要,它为应用提供配置,当应用运行时他是可读的,但是可以被重新加载。

ApplicationContext接口继承了EnvironmentCapable, ListableBeanFactory, HierarchicalBeanFactory, MessageSource, ApplicationEventPublisher, ResourcePatternResolver等接口,这些接口让ApplicationContext具有如下功能:

(1)提供访问应用组件的bean工厂方法,该功能继承自ListableBeanFactory接口。

(2)提供通用的方式加载文件资源,该功能继承自ResourceLoader接口。

(3)将事件发布给注册的监听器。该功能继承自ApplicationEventPublisher接口。

(4)解决消息和支持国际化,该功能继承自MessageSource接口。

(5)从父上下文继承。子上下文中的定义总是优先考虑。例如,整个web应用有一个父上下文,而每个servlet都有自己独立的子上下文。

除了标准BeanFactory的能力,ApplicationContext还实现检测和调用ApplicationContextAware 、ResourceLoaderAware、ApplicationEventPublisherAware and MessageSourceAware。

上述就是简单的将官方API翻译了一遍~~ 仔细的读者可能脑海中,冒出了至少有两个问题。

问题1:上述功能第2条说ApplicationContext加载文件资源的功能继承自ResourceLoader,而该ApplicationContext接口在声明是并没有没有继承该接口,那么是怎么继承的?

答:仔细看ApplicationContext接口的声明,发现它继承了ResourcePatternResolver。跟进源码发现ResourcePatternResolver继承了ResourceLoader。所以说ResourceLoader和ApplicationContext是爷孙关系,并不是父子关系。

那么问题又来了,框架设计者为什么要这么“多此一举”?

源码中的类注释是这样写的:

Strategy interface for resolving a location pattern (for example,an Ant-style path pattern) into Resource objects.

这是一个策略接口,这样做的目的是为了将一个 location模式解析到一个资源对象中,例如Ant风格的路径模式。(这里好像还是不理解,原谅我的菜~,不如先看看ResourceLoader接口回头再来理解。

ResourceLoader接口源码:

 /**
* Strategy interface for loading resources (e.. class path or file system
* resources). An {@link org.springframework.context.ApplicationContext}
* is required to provide this functionality, plus extended
* {@link org.springframework.core.io.support.ResourcePatternResolver} support.
*
* <p>{@link DefaultResourceLoader} is a standalone implementation that is
* usable outside an ApplicationContext, also used by {@link ResourceEditor}.
*
* <p>Bean properties of type Resource and Resource array can be populated
* from Strings when running in an ApplicationContext, using the particular
* context's resource loading strategy.
*
* @author Juergen Hoeller
* @since 10.03.2004
* @see Resource
* @see org.springframework.core.io.support.ResourcePatternResolver
* @see org.springframework.context.ApplicationContext
* @see org.springframework.context.ResourceLoaderAware
*/
public interface ResourceLoader { /** Pseudo URL prefix for loading from the class path: "classpath:" */
String CLASSPATH_URL_PREFIX = ResourceUtils.CLASSPATH_URL_PREFIX; /**
* Return a Resource handle for the specified resource location.
* <p>The handle should always be a reusable resource descriptor,
* allowing for multiple {@link Resource#getInputStream()} calls.
* <p><ul>
* <li>Must support fully qualified URLs, e.g. "file:C:/test.dat".
* <li>Must support classpath pseudo-URLs, e.g. "classpath:test.dat".
* <li>Should support relative file paths, e.g. "WEB-INF/test.dat".
* (This will be implementation-specific, typically provided by an
* ApplicationContext implementation.)
* </ul>
* <p>Note that a Resource handle does not imply an existing resource;
* you need to invoke {@link Resource#exists} to check for existence.
* @param location the resource location
* @return a corresponding Resource handle (never {@code null})
* @see #CLASSPATH_URL_PREFIX
* @see Resource#exists()
* @see Resource#getInputStream()
*/
Resource getResource(String location); /**
* Expose the ClassLoader used by this ResourceLoader.
* <p>Clients which need to access the ClassLoader directly can do so
* in a uniform manner with the ResourceLoader, rather than relying
* on the thread context ClassLoader.
* @return the ClassLoader
* @see org.springframework.util.ClassUtils#getDefaultClassLoader()
*/
@Nullable
ClassLoader getClassLoader(); }

一个静态常量CLASSPATH_URL_PREFIX = "classpath:"

两个成员方法getResource、getClassLoader

多余的这里我就不翻译了,相信大部分同学的英语水准都比四级都差点没过的我要强。

仔细看getResource(String location)返回值是Resource ,这又是个什么鬼?继续点进去看源码发现其声明如下:

public interface Resource extends InputStreamSource

基本上可以猜到封装了一个输入流,加一些包装的方法等。如果InputStream的原理不懂的,可以看一下java的InputStream源码。

尼玛~本章的内容我没记错的话好像是ApplicationContext,似乎是有点跑偏了,接下来回到问题1抛出的新问题(还是有点偏,大家先忍忍)。

为什需要一个ResourcePatternResolver,我们看看该接口的源码:

 public interface ResourcePatternResolver extends ResourceLoader {

     /**
* Pseudo URL prefix for all matching resources from the class path: "classpath*:"
* This differs from ResourceLoader's classpath URL prefix in that it
* retrieves all matching resources for a given name (e.g. "/beans.xml"),
* for example in the root of all deployed JAR files.
* @see org.springframework.core.io.ResourceLoader#CLASSPATH_URL_PREFIX
*/
String CLASSPATH_ALL_URL_PREFIX = "classpath*:"; /**
* Resolve the given location pattern into Resource objects.
* <p>Overlapping resource entries that point to the same physical
* resource should be avoided, as far as possible. The result should
* have set semantics.
* @param locationPattern the location pattern to resolve
* @return the corresponding Resource objects
* @throws IOException in case of I/O errors
*/
Resource[] getResources(String locationPattern) throws IOException; }

里面有一个常量CLASSPATH_ALL_URL_PREFIX = "classpath*:"

回顾父接口常量CLASSPATH_URL_PREFIX = "classpath:"

发生了什么?多了一个“*”号!可能到这里很多读者已经想起来Ant-style path pattern的三个符号了

? 匹配任何单字符  
* 匹配0或者任意数量的字符  
** 匹配0或者更多的目录

getResources方法的返回值是个数组,到此恍然大悟,一个模式可能匹配多个文件。到此问题1算是解决了~

问题2:官方文档似乎没有介绍继承EnvironmentCapable, HierarchicalBeanFactory两个接口有什么用?

我们先看EnvironmentCapable源码:

 public interface EnvironmentCapable {

     /**
* Return the {@link Environment} associated with this component.
*/
Environment getEnvironment(); }

该接口表面上的作用是提供一个Environment的引用,这有什么用?

源码的类注释解释了,大概意思是:spring中所有context都继承了该接口,这样做的目的是用于类型检查,例如框架中有些与用户定义的BeanFactory交互的方法,这些方法有些就需要使用用户定义的BeanFactory的环境变量。这个时候就要看其是否是EnvironmentCapable接口的子类了。

注释还强调了ConfigurableApplicationContext重写了getEnvironment,其返回值是ConfigurableEnvironment。

ConfigurableApplicationContext又是哪来的,后面进入本章高潮了再介绍。

再看HierarchicalBeanFactory源码:

 public interface HierarchicalBeanFactory extends BeanFactory {

     /**
* Return the parent bean factory, or {@code null} if there is none.
*/
@Nullable
BeanFactory getParentBeanFactory(); /**
* Return whether the local bean factory contains a bean of the given name,
* ignoring beans defined in ancestor contexts.
* <p>This is an alternative to {@code containsBean}, ignoring a bean
* of the given name from an ancestor bean factory.
* @param name the name of the bean to query
* @return whether a bean with the given name is defined in the local factory
* @see BeanFactory#containsBean
*/
boolean containsLocalBean(String name); }

HierarchicalBeanFactory也继承了BeanFactory,为什么是也?还记得ApplicationContext的功能1吗?因为ListableBeanFactory肯定继承了BeanFactory(不要问我为什么知道)

HierarchicalBeanFactory有两个方法:(1)得到父bean factory.(2)返回本地bean工厂是否包含给定名称的bean,忽略在祖先上下文中定义的bean。

留个思考题:为什么要这么设计?为什么??

到此,ApplicationContext继承的多个接口我们都知道其作用了,有几个API中解释了的接口还没深入源码,感兴趣的可以继续~~~

ApplicationContext继承了那么多功能,那么它自己有什么独特的呢?

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAd0AAAC+CAYAAABwKtUuAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAACkmSURBVHhe7Z1rkBZVmuf5aPhJQzd2Z1ZmDWNjIzY0SmOj/QB+sMNYp5ktyiplWkDKaWGYghIaR2XHVqAdL8FNkYsQLlC7XIQC6R7LHrCY3hiHwB5Z3dEZNWysbcQpLS/QNS1d0lAijs+ea+Y5J0/e3jffrHor/7+IRzPP5cmT+VacHyfrrcxJH312nuLizTffRCAQCAQCUVBEpMvRlaB++v/2TRHvfvRbBAKBQFQ8LOlyINvGAPEiEAgEwpIuhNtYIF4EAoGodgTS5UC6jQXSRSAQiGpHIF0Itxy4eN8Z/C0CgUAgKhip0j134aI3vv1WNQC5gHQRCASiupEo3fMXvqEru39Cf3BfnxX/5t6f0Ef/8jvVCuQB0kUgEIjqRqp0J9/3otoL+S/L+yHdGpHSPYNAIBCICkaqdK9i0j35BVlx/TIp3TeGyRtlMtgzjSYtPRLZbgTd3d1BuCTVmUC6CAQCUd1Ile6/X/Ii9X/AZGHEdQ9L6X73kV5vpHFk6SSaNCmMaT2DqiY/ZUtXk2XbB6SLQCAQ1Y1U6f4+k+6av79oxX9+6GUh3Y9+/VtvxHOElnLRWmIcpJ5pblkCgz00bdJSlknvNla0Jq5Q+b6vLAlIF4FAIKobqdL9gz/vo8n32cHLPv7NOdUqO/GClDLO5M4xlC4nSappwuVw6b79z2cQCAQCUcFIlG4aV7FV8L9b9FMRvz3/tSqNQ65o4/zIbznr28zmtuDIUpo0rYcG+f+N29JctnG3l/W2eSvbPLZ1i5vnVuVZ8Mk1i3A5kC4CgUBUN+qS7u8t/isa/vIruuaB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C4AAABQEpAuAAAAUBKQLgAAAFASkC4AAABQEpAuAAAAUBKQLgAAAFASkC4AAABQEpAuAAAAUBKQLgAAAFASkC4AAABQEpAuAAAAUBKQLgAAAFASkC4AAABQEpAuAAAAUBKQLgAAAFASkC4AAABQCkT/H00Or+H2dxWtAAAAAElFTkSuQmCCAA==" alt="" />

其他方法都好理解,这里似乎有1个问题:这里为什么要暴露出AutowireCapableBeanFactory?搞明白该接口的作用解决该问题的希望可能会更大(这不废话么,哈哈)。

TODO:AutowireCapableBeanFactory

下面介绍ApplicationContext的层级关系

太多了,部分没展开。大家是否发现了自己熟悉的context,例如ClassPathXmlApplicationContext、FileSystemXmlApplicationContext、XmlWebApplicationContext等。

类图懒得画了,找了一个,如下(来自:http://blog.csdn.net/h12kjgj/article/details/53725507)

TODO:解读常用的context源码

下文是本文梳理的重点(来自:http://blog.csdn.net/h12kjgj/article/details/53725507)

Spring随笔之ApplicationContext的更多相关文章

  1. 【Spring】Spring随笔索引

    Spring随笔索引 [Spring]Spring bean的实例化 [Spring]手写Spring MVC [Spring]Spring Data JPA

  2. spring BeanFactory及ApplicationContext中Bean的生命周期

    spring bean 的生命周期 spring BeanFactory及ApplicationContext在读取配置文件后.实例化bean前后.设置bean的属性前后这些点都可以通过实现接口添加我 ...

  3. spring中获取applicationContext

    常用的5种获取spring 中bean的方式总结: 方法一:在初始化时保存ApplicationContext对象代码:ApplicationContext ac = new FileSystemXm ...

  4. Spring的配置文件ApplicationContext.xml配置头文件解析

    Spring的配置文件ApplicationContext.xml配置头文件解析 原创 2016年12月16日 14:22:43 标签: spring配置文件 5446 spring中的applica ...

  5. Spring基础04——ApplicationContext

    1.ApplicationContext简述 ApplicationContext代表IOC容器,在SpringIOC容器中读取Bean配置创建Bean实例之前,必须对它进行实例化,只有在容器实例化后 ...

  6. 死磕Spring之IoC篇 - Spring 应用上下文 ApplicationContext

    该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读 Spring 版本:5.1. ...

  7. Spring使用非applicationContext.xm 默认名的配置文件的配置

    Spring默认的配置文件是applicationContext.xml,但是有些时候,希望拆分Spring的配置文件,让其单一化,每一个都只进行自己的配置,如图所示 那么就需要在web.xml中配置 ...

  8. Spring中的ApplicationContext事件机制

    ApplicationContext的事件机制是观察者设计模式的实现,通过ApplicationEvent类和ApplicationListerner接口来实现. 1. 创建EmailEvent pu ...

  9. spring获取webapplicationcontext,applicationcontext几种方法详解

    法一:在初始化时保存ApplicationContext对象代码: ApplicationContext ac = new FileSystemXmlApplicationContext(" ...

随机推荐

  1. 《c程序设计语言》读书笔记-3-3-速记扩充

    #include <io.h> #include <stdio.h> #include <string.h> #include <stdlib.h> i ...

  2. Pandas之Series

    # Series 数据结构 # Series 是带有标签的一维数组,可以保存任何数据类型(整数,字符串,浮点数,Python对象等),轴标签统称为索引 import numpy as np impor ...

  3. github 小白教程

    工作整天在忙,也没好好有整块的时间去学学东西,记录一下github的学习过程,以便日后好回顾,我一直坚信只有被大家分享的知识,才是好知识. github是什么?一定有人会有这样的疑问.那么如果说到gi ...

  4. 让chrome支持本地Ajax请求

    Chrome的安全机制不能支持ajax的本地访问, 例如: 在JavaScript里面访问 URL:file:///E:/test.html,Chrome 浏览器报错:XMLHttpRequest c ...

  5. Angular(二)

    <!DOCTYPE html> <html lang="en" ng-app='myApp'> <head> <meta charset= ...

  6. 静态页面之间的转发与json与ajax做到动态数据

    我们见过很多使用jsp ,php,asp的动态网页技术的网站了,我们知道如果一个网站内容更新频率极低,而内容量不是十分庞大时,这样的网站(一次开发完成后不会需要较多的维护成本)的完全可以使用全部使用静 ...

  7. MFC 获得各类指针、句柄的方法(转)

    原文转自 https://blog.csdn.net/abcjennifer/article/details/7480019 1.MFC中获取常见类句柄<视图类,文档类,框架类,应用程序类> ...

  8. Linux学习总结—缺页中断和交换技术【转】

    三.Linux缺页中断处理 转自:http://blog.csdn.net/cxylaf/article/details/1626534 1.请求调页中断: 进程线性地址空间里的页面不必常驻内存,例如 ...

  9. 关于backBarButtonItem的N种方法

    替换返回按钮的文字 很多app的要求所有的返回按钮的title都是“返回”,如果上一层题目文字太多,下一层的返回按钮文字就会显示不完全,而且这样可以使软件显得整洁. 方法一: 最普通的想法,A界面的n ...

  10. xpath测试工具 xpath调试工具

    其实这个工具没什么介绍的了 因为目前有项目中需要到了xpath语法,然后呢,有没有什么好的工具 大部分都是联网的,个人比较喜欢离线的工具包 所以顺手就写了一个小工具来测试xpath语法的正确性 so, ...