编译问题

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)

org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.checkNameUniqueness(String
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源码分析的更多相关文章

  1. spring源码分析之spring-core总结篇

    1.spring-core概览 spring-core是spring框架的基石,它为spring框架提供了基础的支持. spring-core从源码上看,分为6个package,分别是asm,cgli ...

  2. Spring源码分析——BeanFactory体系之抽象类、类分析(二)

    上一篇分析了BeanFactory体系的2个类,SimpleAliasRegistry和DefaultSingletonBeanRegistry——Spring源码分析——BeanFactory体系之 ...

  3. Spring源码分析——BeanFactory体系之抽象类、类分析(一)

    上一篇介绍了BeanFactory体系的所有接口——Spring源码分析——BeanFactory体系之接口详细分析,本篇就接着介绍BeanFactory体系的抽象类和接口. 一.BeanFactor ...

  4. Spring源码分析——资源访问利器Resource之实现类分析

    今天来分析Spring的资源接口Resource的各个实现类.关于它的接口和抽象类,参见上一篇博文——Spring源码分析——资源访问利器Resource之接口和抽象类分析 一.文件系统资源 File ...

  5. spring源码分析(二)Aop

    创建日期:2016.08.19 修改日期:2016.08.20-2016.08.21 交流QQ:992591601 参考资料:<spring源码深度解析>.<spring技术内幕&g ...

  6. 【Spring源码分析】Bean加载流程概览

    代码入口 之前写文章都会啰啰嗦嗦一大堆再开始,进入[Spring源码分析]这个板块就直接切入正题了. 很多朋友可能想看Spring源码,但是不知道应当如何入手去看,这个可以理解:Java开发者通常从事 ...

  7. 【Spring源码分析】非懒加载的单例Bean初始化过程(上篇)

    代码入口 上文[Spring源码分析]Bean加载流程概览,比较详细地分析了Spring上下文加载的代码入口,并且在AbstractApplicationContext的refresh方法中,点出了f ...

  8. 【Spring源码分析】非懒加载的单例Bean初始化过程(下篇)

    doCreateBean方法 上文[Spring源码分析]非懒加载的单例Bean初始化过程(上篇),分析了单例的Bean初始化流程,并跟踪代码进入了主流程,看到了Bean是如何被实例化出来的.先贴一下 ...

  9. 【Spring源码分析】非懒加载的单例Bean初始化前后的一些操作

    前言 之前两篇文章[Spring源码分析]非懒加载的单例Bean初始化过程(上篇)和[Spring源码分析]非懒加载的单例Bean初始化过程(下篇)比较详细地分析了非懒加载的单例Bean的初始化过程, ...

随机推荐

  1. js 遇到 Permission denied to access property ***

    在开发过程 子页面刷新父页面时,中遇到的 Permission denied to access property *** 问题,处理如下: 这是一个跨域的问题,其实很简单 就是子页面所在域名不在父页 ...

  2. css 属性之绝对定位

    <html><head><style type="text/css">h2.pos_abs{position:absolute;left:100 ...

  3. 导出数据到excel

    Protected Sub cmdOrderExport_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdOrderExp ...

  4. 使用MFC开发有十多年了,结合自身的体会,随便说几句(不能样样都依赖别人,C体系的人,绝对不怕人踢馆)

    挺长时间了吧,这个帖子还没沉下去,使用MFC开发有十多年了,结合自身的体会,随便说几句:1.MFC是一个C++的基础类库,封装了绝大多数的API函数,主要是用来创建带UI的应用程序,服务端程序或着不带 ...

  5. @action 注解

    ================================================= 下载 注解配置 private String fileName; private String co ...

  6. 强联通 HDU 1269

    第一道强联通的题目纪念一下! 主要是模版 tarjan算法 #include <iostream> #include <cstdlib> #include <cstdio ...

  7. pip常用命令

    以flask为例. 1. 安装 # pip install flask 安装 flask. # pip install flask==1.0 安装 1.0版本的flask # pip install ...

  8. Drainage Ditches - poj 1273(网络流模板)

    题意:1是源点,m是汇点,求出来最大流量,没什么好说的就是练习最大流的模板题 ************************************************************* ...

  9. MVC控制器方法返回类型

    控制器公开控制器操作.操作是控制器上的方法,在浏览器的地址栏中输入特定 URL 时被调用.例如,假设要请求下面的 URL: http://localhost/Product/Index/3 在这种情况 ...

  10. org.apache.struts.chain.commands.InvalidPathException: No action config found for the specified url.

    No action config found for the specified url url路径下找不到action,原因是stuts-config.xml文件配置错误. demo的项目文件如下: ...