SpringBoot自动配置AutoConfiguration核心流程源码解析

SpringBoot自动配置

@SpringBootApplication包含@SpringBootConfiguration、@EnableAutoConfiguration、@ComponentScan、@ConfigurationPropertiesScan

SpringApplication.run启动流程中与自动配置相关流程:

  1. SpringApplication启动

    org.springframework.boot.SpringApplication#run(java.lang.Class<?>, java.lang.String…)

  2. 创建ApplicationContext

    org.springframework.boot.SpringApplication#createApplicationContext

  3. 注册ConfigurationClassPostProcessor

    org.springframework.context.annotation.AnnotationConfigUtils#registerAnnotationConfigProcessors(org.springframework.beans.factory.support.BeanDefinitionRegistry)

  4. refresh invoke BeanFactoryPostProcessor

    org.springframework.context.support.AbstractApplicationContext#invokeBeanFactoryPostProcessors

  5. postProcess @Configuration

    org.springframework.context.annotation.ConfigurationClassPostProcessor#postProcessBeanDefinitionRegistry

  6. process启动类SpringApplication配置类

    org.springframework.context.annotation.ConfigurationClassParser#doProcessConfigurationClass

  7. ComponentSacn,默认扫描启动类包路径

    org.springframework.context.annotation.ComponentScanAnnotationParser#parse

  8. process imports

    org.springframework.context.annotation.ConfigurationClassParser#processImports

  9. 解析@SpringBootApplication注解的Imports,包括AutoConfigurationImportSelector
    -org.springframework.context.annotation.ConfigurationClassParser#processImports

    • org.springframework.boot.autoconfigure.AutoConfigurationPackages$Registrar
    • org.springframework.boot.autoconfigure.AutoConfigurationImportSelector
    • org.springframework.boot.context.properties.EnableConfigurationPropertiesRegistrar
    • org.springframework.boot.context.properties.ConfigurationPropertiesScanRegistrar
  10. 处理ImportSelector
    org.springframework.context.annotation.ConfigurationClassParser.DeferredImportSelectorHandler#process

  11. 加载EnableAutoConfiguration扩展点
    org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.AutoConfigurationGroup#process

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值