• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

无信不立

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

【springboot】阅读

一、模式

java.awt.headless

 

org.springframework.boot.SpringApplication

springboot项目的:org.springframework.boot.SpringApplication

new该类时,会去系统文件加载如下这些接口:

org.springframework.context.ApplicationContextInitializer

org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer

org.springframework.boot.context.ContextIdApplicationContextInitializer

org.springframework.boot.context.config.DelegatingApplicationContextInitializer

org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer

org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer

 

org.springframework.context.ApplicationListener

org.springframework.boot.ClearCachesApplicationListener

org.springframework.boot.builder.ParentContextCloserApplicationListener

org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor

org.springframework.boot.context.FileEncodingApplicationListener

org.springframework.boot.context.config.AnsiOutputApplicationListener

org.springframework.boot.context.config.ConfigFileApplicationListener

1、(加载resources目录下的application.yml文件,和application.properties 文件)

2、对配置文件处理,借助如下处理类。接口为:org.springframework.boot.env.EnvironmentPostProcessor

  • org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor
  • org.springframework.boot.env.SpringApplicationJsonEnvironmentPostProcessor
  • org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor
  • org.springframework.boot.reactor.DebugAgentEnvironmentPostProcessor

 

======加载配置文件的类========

org.springframework.boot.context.config.ConfigFileApplicationListener.Loader

org.springframework.boot.env.PropertySourceLoader

org.springframework.boot.env.PropertiesPropertySourceLoader

org.springframework.boot.env.YamlPropertySourceLoader

 

 

 

org.springframework.boot.context.config.DelegatingApplicationListener

org.springframework.boot.context.logging.ClasspathLoggingApplicationListener

org.springframework.boot.context.logging.LoggingApplicationListener

org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener

 


mainApplicationClass

当前系统启动的主类

 

 

 

二、启动过程

(1)从配置文件中获取该接口的实现类:SpringApplicationRunListeners  ---》org.springframework.boot.context.event.EventPublishingRunListener

(2)执行starting事件ApplicationStartingEvent()==> ApplicationListener去执行

(3)准备上下文环境:org.springframework.core.env.ConfigurableEnvironment (接口)==》org.springframework.core.env.StandardEnvironment

             上下文环境准备事件:ApplicationEnvironmentPreparedEvent ==> ApplicationListener去执行

         命令行参数:commandLineArgs    ===》命令行参数解析器:org.springframework.core.env.SimpleCommandLineArgsParser

             org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource

(4)创建appLicationContext对象

  org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext

  org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext

  org.springframework.context.annotation.AnnotationConfigApplicationContext(默认是这个)

 

(5)基于spi机制,从spring.factories中获取错误上报器:

  接口:org.springframework.boot.SpringBootExceptionReporter

  上线类:org.springframework.boot.diagnostics.FailureAnalyzers

  (6) 预处理applicationContext对象

  -->设置上下文环境:org.springframework.core.env.StandardEnvironment

  -->设置相应的组件:

    beanNameGenerator(beanName发电机):

    resourceLoader(源文件loader):

    classLoader(类加载器):

    ConversionService(类型转换器):

  -->执行服务初始化器ApplicationContextInitializer

    org.springframework.context.ApplicationContextInitializer=\

    org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\

    org.springframework.boot.context.ContextIdApplicationContextInitializer,\

    org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\

    org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer,\

    org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer

    org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer,\

    org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener

  (7) 对ApplicationContext执行资源加载过程

    ->创建BeanDefinitionLoader:org.springframework.boot.BeanDefinitionLoader

    sources(资源)

    AnnotatedBeanDefinitionReader(注解读取器)
      ==>【初始化该类时,会调用AnnotationConfigUtils.registerAnnotationConfigProcessors,向spring容器中注入ConfigurationClassPostProcessor】

      ==>org.springframework.context.annotation.ConfigurationClassParser (会对每一个配置了符合spring要求的注解类进行扫描到)

    XmlBeanDefinitionReader(xml配置文件读取器)

    GroovyBeanDefinitionReader(groovy配置读取器)

    ClassPathBeanDefinitionScanner(类路经排除器)

    ResourceLoader(资源加载器)

  ->执行资源加载(将xml或注解或groovy的配置的bean全部加载到applicationContext中)

      ==>在load阶段,会将启动的主类,转换成一个AnnotatedGenericBeanDefinition注入到spring容器中。等待refresh阶段,被ConfigurationClassPostProcessor处理,进行资源加载。

  ->SpringApplicationRunListeners.contextLoaded

(8)刷新applicationContext容器

  ->refresh方法:处理bean,初始化监听器

    org.springframework.context.annotation.internalConfigurationAnnotationProcessor(内部配置注解处理器)

    org.springframework.context.annotation.ConfigurationClassPostProcessor启动配置的关键类。

  ->SpringApplicationRunListeners.contextLoaded.started

(9)执行后置的方法

  ->ApplicationRunner

  ->CommandLineRunner

 (10)SpringApplicationRunListeners.running

 

 

https://blog.csdn.net/andy_zhang2007/article/details/94980834(spring-boot启动容器)

 

posted on 2020-03-18 15:08  无信不立  阅读(133)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3