zoukankan      html  css  js  c++  java
  • 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)

    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:workspacespringspring-contextsrc estjavaorgspringframeworkcontextannotationComponentScanParserTests.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)

  • 相关阅读:
    第一周2016/9/16
    团队项目计划会议
    电梯演讲视频
    团队项目成员与题目(本地地铁查询app)
    地铁查询相关问题汇总
    延长zencart1.5.x后台的15分钟登录时间和取消90天强制更换密码
    zencart1.5.x版管理员密码90天到期后台进入不了的解决办法
    通过SSH解压缩.tar.gz、.gz、.zip文件的方法
    html标签被div嵌套页面字体变大的解决办法
    zencart批量插入TEXT文本属性attributes
  • 原文地址:https://www.cnblogs.com/usual2013blog/p/3986106.html
Copyright © 2011-2022 走看看