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的初始化过程, ...
随机推荐
- js 得到当前季度
Date.prototype.getQuarter = function() { var month = this.getMonth(); if(month < 3) { return '第一季 ...
- SCJP_104——题目分析(1)
1.1) public class ReturnIt{2) returnType methodA(byte x, double y){3) return (short)x/y*2;4) }5) }wh ...
- bzoj1115: [POI2009]石子游戏Kam
Description 有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证操作后仍然满足初始时的条件谁没有石子可移时输掉游戏 ...
- Swift互用性:与 Cocoa 数据类型共舞(Swift 2.0版)-b
本节内容包括: 字符串(Strings) 数值(Numbers) 集合类(Collection Classes) 错误(Errors) Foundation数据类型(Foundation Data T ...
- 蓝牙-b
最近智能家居比较火,好多公司开始开发通过蓝牙对智能家居进行连接控制!下面,我就把自己总结的蓝牙方面的知识分享一下!求吐槽!!!!O(∩_∩)O... 1.导入头文件#import <CoreBl ...
- SpringMVC入门1
SpringMVC核心类与接口 •DispatcherServlet 前端控制器(也称总控制器),把请求给转发到具体的控制类 •HandlerMapping 映射处理器,负责映射中央处理器转发给con ...
- nginx的使用配置
nginx为反向代理服务器,可以反向代理不同域名转向不同的具体服务器.可以用于负载压力或是同一台机器使用不同域名进行访问. 以下片段是服务器配置: #user cmcc; worker_process ...
- redis 源码分析
参考: http://redisbook.readthedocs.org/en/latest/index.html http://www.databaseskill.com/3421161/ The ...
- db file sequential read等待事件的一点研究
db file sequential read等待事件有3个参数:file#,first block#,和block数量. 这个等待事件有3个参数P1,P2,P3, 其中P1代表Oracle要读取的文 ...
- Linux下apache的停止、开启、重启
有两种途径 一. service httpd stop(停止) service httpd start(开始) service httpd restart(重启) 这种方法,是系统自带的 二. 或者到 ...