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的初始化过程, ...
随机推荐
- linux内核移植 I
根据tx2440的文档, 目标也比较简单, 先编译成功, 再烧录, 根文件系统, busybox 这些. A. 准备 1. 解压tar, 修改根Makefile ARCH ?= arm CROSS_C ...
- CentOS 基础安装
1. 下载了 CentOS 的最小安装版本 与 VMware,基础安装流程参考百度经验:http://jingyan.baidu.com/article/eae0782787b4c01fec54853 ...
- iOS开发网络篇—XML数据的解析
iOS开发网络篇—XML数据的解析 iOS开发网络篇—XML介绍 一.XML简单介绍 XML:全称是Extensible Markup Language,译作“可扩展标记语言” 跟JSON一样,也是 ...
- Nhibernate 分页
public IList<Student> GetStudentByPage(int pageSize, int pageIndex, string SName) { ISession s ...
- (未解决)android studio:com.android.support:appcompat-v7:22+ Could not found
错误信息如下: Error:Could not +. Searched in the following locations: https://jcenter.bintray.com/com/andr ...
- HDU 3446 daizhenyang's chess
http://acm.hdu.edu.cn/showproblem.php?pid=3446 题意:一个棋盘,有个KING,有一些能走的点,每次只能走到没走过的地方,没路可走的输,求先手是否必胜. 思 ...
- C51指针的使用
指针就是指变量或数据所在的存储区地址.如一个字符型的变量 STR 存放在内存单元DATA 区的 51H 这个地址中,那么 DATA 区的 51H 地址就是变量 STR 的指针.在 C 语言中指针是一个 ...
- Windows系统编程之进程间通信
Windows系统编程之进程间通信作者:北极星2003来源:看雪论坛(www.pediy.com)Windows 的IPC(进程间通信)机制主要是异步管道和命名管道.(至于其他的IPC方式,例如内存映 ...
- html5中使用标签支持视频播放
<!--定义视频--> <!-- <video src="E:/ext-4.2.1.883/learnHtml5/Wildlife.wmv" control ...
- 腾讯CDC谈扁平化设计
扁平化设计无疑是当前讨论最多,最火的设计形式,自ios7面世以来更是将扁平化设计的讨论推向风口浪尖. 在这里我不想分析拟物设计和扁平化设计的优劣,更不想说谁更好!在形式服从内容的今天,我只能说哪种设计 ...