本文简单的分析下spring对某个目录下的class资源是如何做到全部的加载 PathMatchingResourcePatternResolver#getResources PathMatchingResourcePatternResolver是ResourcePatternResolver的实现类,主要实现的方法为getResources(String locationPattern),具体代码如下,以classpath*:com/question/**/*.class为例 public R…
承接前文Spring源码情操陶冶-自定义节点的解析,本文讲述spring通过context:component-scan节点干了什么事 ComponentScanBeanDefinitionParser#私有属性 罗列下context:component-scan可填的基础属性 private static final String BASE_PACKAGE_ATTRIBUTE = "base-package"; private static final String RESOURCE…
前言-阅读源码有利于陶冶情操,本文承接前文Spring源码情操陶冶-AbstractApplicationContext 约束: 本文指定contextClass为默认的XmlWebApplicationContext 从属AbstractApplicationContext#refresh方法 AbstractApplicationContext#obtainFreshBeanFactory 该方法主要完成创建Bean工厂,涉及到解析spring文件,代码清单如下 protected Conf…
前言-阅读源码有利于陶冶情操,本文承接前文Spring源码情操陶冶-ContextLoaderListener 静态代码块内容 ContextLoader在被主动调用的时候,会执行其的一个静态块,代码如下 static { // Load default strategy implementations from properties file. // This is currently strictly internal and not meant to be customized // by…
前言-阅读源码有利于陶冶情操,本文承接前文Spring源码情操陶冶-AbstractApplicationContext#obtainFreshBeanFactory 前文提到最关键的地方是解析bean xml配置文件,废话不多说,直接上代码清单 //正如官方注释所说,解析import标签.alias标签.bean标签和自定义的标签 protected void parseBeanDefinitions(Element root, BeanDefinitionParserDelegate del…
本文针对spring配置的context:property-placeholder作下简单的分析,承接前文Spring源码情操陶冶-自定义节点的解析 spring配置文件应用 <context:property-placeholder location="classpath:context.properties"> PropertyPlaceholderBeanDefinitionParser-继承关系 配置文件解析类的继承关系如下 * AbstractBeanDefini…
承接前文Spring源码情操陶冶-AbstractApplicationContext#registerListeners 约定web.xml配置的contextClass为默认值XmlWebApplicationContext 直接源码AbstractRefreshableWebApplicationContext#finishBeanFactoryInitialization /** * Finish the initialization of this context's bean fac…
阅读源码有利于陶冶情操,承接前文Spring源码情操陶冶-AbstractApplicationContext#postProcessBeanFactory 约定:web.xml中配置的contextClass为XmlWebApplicationContext 瞧瞧官方注释 /** * Instantiate and invoke all registered BeanFactoryPostProcessor beans, * respecting explicit order if given…
前言-阅读源码有利于陶冶情操,本文承接前文Spring源码情操陶冶-AbstractApplicationContext 约束: 本文指定contextClass为默认的XmlWebApplicationContext 从属AbstractApplicationContext#refresh方法 AbstractApplicationContext#prepareRefresh 代码清单如下 protected void prepareRefresh() { //设置刷新开始时间 this.st…
本文承接前文Spring源码情操陶冶-DefaultBeanDefinitionDocumentReader#parseBeanDefinitions,特开辟出一块新地来啃啃这块有意思的骨头 自定义节点的类型 我们常用的可分为spring/springmvc两类 spring常用的节点类型 context类型 context-component-scan-扫描包内的所有class类并注册为beanDefinition到spring上下文 context-property-placeholder-…