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)

  • 相关阅读:
    .NET Core 3.0 部署在docker上运行
    Docker 微服务教程
    Docker 入门教程
    快速了解 Linux系统信息
    Navicat 连接本地MS-SQL服务器,只能用localhost无法使用127.0.0.1
    安装Ubuntu Server 18.04 并支持远程方式
    AdventureWorks 安装和配置[转自 微软msdn]
    SQL Server 2014 Agent 无法启动
    微信会死么
    ajax+php数据增加查询获取删除
  • 原文地址:https://www.cnblogs.com/usual2013blog/p/3986106.html
Copyright © 2011-2022 走看看