spring源码分析
编译问题
spring-4.0.5.release编译是用jdk8编译的,为啥可以运行在jdk7的环境?
源码分析
spring源码分析,由一个点各个击破,比如依赖注入,autowired。
spring源码深度解析是从整体上解决,慢慢理清头绪。
org.springframework.context.annotation.AnnotationConfigApplicationContext.setBeanNameGenerator(BeanNameGenerator beanNameGenerator)
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
this.reader.setBeanNameGenerator(beanNameGenerator);
this.scanner.setBeanNameGenerator(beanNameGenerator);
getBeanFactory().registerSingleton(
AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, beanNameGenerator);
}
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.registerSingleton(String beanName, Object singletonObject) throws IllegalStateException
Open Declaration org.springframework.context.annotation.AnnotatedBeanDefinitionReader
Convenient adapter for programmatic registration of annotated bean classes. This is an alternative to ClassPathBeanDefinitionScanner, applying the same resolution of annotations but for explicitly registered classes only.
Open Declaration org.springframework.context.annotation.ClassPathBeanDefinitionScanner
A bean definition scanner that detects bean candidates on the classpath, registering corresponding bean definitions with a given registry (BeanFactory or ApplicationContext).
Candidate classes are detected through configurable type filters. The default filters include classes that are annotated with Spring's @Component, @Repository, @Service, or @Controller stereotype.
Also supports Java EE 6's javax.annotation.ManagedBean and JSR-330's javax.inject.Named annotations, if available.
写一些测试用例来加深理解。
//这个方法是用来校验xml中的Bean name '" + foundName + "' is already used in this <beans> element,不能有Bean name重复的情况
org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.checkNameUniqueness(String beanName, List<String> aliases, Element beanElement)
beanName, List<String>
aliases, Element
beanElement)
//这个方法是Register bean definition under primary name.将xml的bean标签中name注册对应的Generic bean(beanClass=org.springframework.tests.sample.beans.DependenciesBean)。
org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(String beanName, BeanDefinition beanDefinition) throws BeanDefinitionStoreException
//component-scan相关源码如下
<context:component-scan base-package="org.springframework.aop.framework" />
void org.springframework.context.config.ContextNamespaceHandler.init()
//调用扫描basepackages方法的地方
org.springframework.context.annotation.ComponentScanAnnotationParser.parse(AnnotationAttributes componentScan, String declaringClass)
org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(Element element, ParserContext parserContext)
org.springframework.context.annotation.AnnotationConfigApplicationContext.AnnotationConfigApplicationContext(String... basePackages)
Ctrl+Shift+G
A default AutowiredAnnotationBeanPostProcessor will be registered by the "context:annotation-config" and "context:component-scan" XML tags.
Remove or turn off the default annotation configuration there if you intend to specify a custom AutowiredAnnotationBeanPostProcessor bean definition.
<p><b>NOTE:</b> Annotation injection will be performed <i>before</i> XML injection;thus the latter configuration will override the former for properties wired through both approaches.
//扫描context:component-scan的例子
D:\workspacespring\spring-context\src\test\java\org\springframework\context\annotation\ComponentScanParserTests.java
org.springframework.context.annotation.ComponentScanParserTests.componentScanWithAutowiredQualifier()
//处理base-package的地方
org.springframework.context.annotation.ComponentScanBeanDefinitionParser.BASE_PACKAGE_ATTRIBUTE = "base-package"
org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(Element element, ParserContext parserContext)
BeanDefinition org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(Element element, ParserContext parserContext)
org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(Element ele, BeanDefinition containingBd)
org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(Element ele)
spring源码分析的更多相关文章
- spring源码分析之spring-core总结篇
1.spring-core概览 spring-core是spring框架的基石,它为spring框架提供了基础的支持. spring-core从源码上看,分为6个package,分别是asm,cgli ...
- Spring源码分析——BeanFactory体系之抽象类、类分析(二)
上一篇分析了BeanFactory体系的2个类,SimpleAliasRegistry和DefaultSingletonBeanRegistry——Spring源码分析——BeanFactory体系之 ...
- Spring源码分析——BeanFactory体系之抽象类、类分析(一)
上一篇介绍了BeanFactory体系的所有接口——Spring源码分析——BeanFactory体系之接口详细分析,本篇就接着介绍BeanFactory体系的抽象类和接口. 一.BeanFactor ...
- Spring源码分析——资源访问利器Resource之实现类分析
今天来分析Spring的资源接口Resource的各个实现类.关于它的接口和抽象类,参见上一篇博文——Spring源码分析——资源访问利器Resource之接口和抽象类分析 一.文件系统资源 File ...
- spring源码分析(二)Aop
创建日期:2016.08.19 修改日期:2016.08.20-2016.08.21 交流QQ:992591601 参考资料:<spring源码深度解析>.<spring技术内幕&g ...
- 【Spring源码分析】Bean加载流程概览
代码入口 之前写文章都会啰啰嗦嗦一大堆再开始,进入[Spring源码分析]这个板块就直接切入正题了. 很多朋友可能想看Spring源码,但是不知道应当如何入手去看,这个可以理解:Java开发者通常从事 ...
- 【Spring源码分析】非懒加载的单例Bean初始化过程(上篇)
代码入口 上文[Spring源码分析]Bean加载流程概览,比较详细地分析了Spring上下文加载的代码入口,并且在AbstractApplicationContext的refresh方法中,点出了f ...
- 【Spring源码分析】非懒加载的单例Bean初始化过程(下篇)
doCreateBean方法 上文[Spring源码分析]非懒加载的单例Bean初始化过程(上篇),分析了单例的Bean初始化流程,并跟踪代码进入了主流程,看到了Bean是如何被实例化出来的.先贴一下 ...
- 【Spring源码分析】非懒加载的单例Bean初始化前后的一些操作
前言 之前两篇文章[Spring源码分析]非懒加载的单例Bean初始化过程(上篇)和[Spring源码分析]非懒加载的单例Bean初始化过程(下篇)比较详细地分析了非懒加载的单例Bean的初始化过程, ...
随机推荐
- 面向对象设计模式之Flyweight享元模式(结构型)
动机:采用纯粹对象方案的问题在于大量细粒度的对象会很快充斥在系统中,从而带来很高的运行代价——主要指内存需求方面的代价.如何在避免大量细粒度对象问题的同 时,让外部客户程序仍然能够透明地使用面向对象的 ...
- DEDE站点从网站根目录移到子目录
修改DedeCms系统配置参数-站点设置 a.站点根网址修改为:http://域名/子目录 b.网页主页链接:/子目录 修改DedeCms系统配置参数-核心设置 a.安装目录:/子目录 批量修改原数据 ...
- django HttpRequest
request.path 除域名以外的请求路径,以正斜杠开头 "/hello/" request.get_host() 主机名(比如,通常所说的域名) "127.0.0. ...
- python——BS解析器
- JS之路——Math数学对象
Math数学对象 ceil(数值)大于或等于该数的最小整数 floor(数值)小于或等于该数的最大整数 min(数值1,数值2)返回最小值 max(数值1,数值2)返回最大值 pow(数值1,数值2) ...
- stringstream复用【原创】
stringstream ss("123"); int i=0; ss>>i; ss.str(""); ----清空内容 ss.c ...
- html动态编辑框
简述: 随着在输入框中增加字符,动态矿高度增加(IE9及以上 chrome firefox) 由于IE8 不支持oninput函数,所以不能实现此效果 事件函数: function feedDivO ...
- linxu安装OSX
下载OS X Mavericks 10.9 Retail VMware Image安装vmware10.01打开unlock-all-v110,运行install.sh 打开vmx. 更新系统. 安装 ...
- Excel进行项目规划的好处
1.表格的方式 2.多个工作表 3.插入图片 4.清晰的规划 5.大众都能看得懂 6.辅助一些数据表设计,其他的流程设计 7.对项目该做什么,进度等等有一个明确的认识 8.项目管理,吃透需求,对进度把 ...
- [Java] TreeMap - 源代码学习笔记
TreeMap 实现了 SortedMap 和 NavigableMap 接口,所有本文还会记录 SortedMap 和 NavigableMap 的阅读笔记. SortedMap 1. 排序的比较应 ...