Springboot 启动过程中可定制“插槽”

sequenceDiagram
	participant refresh context
	participant SpringApplication
	participant A
	participant B
	participant C
	participant D
	participant E
    SpringApplication ->>+ B: B.starting()
    B ->>+ C: ApplicationStartingEvent
    C -->>- B: 
    B -->>- SpringApplication: 
    SpringApplication ->>+ B: B.environmentPrepared()
    B ->>+ C: ApplicationEnvironmentPreparedEvent
    C ->>+ D: D.postProcessEnvironment()
    D ->>+ E: E.load()
    E -->>- D: 
    D -->>- C: 
    C -->>- B: 
    B -->>- SpringApplication: 
    SpringApplication ->>+ A: A.initialize()
    A -->>- SpringApplication: 
    SpringApplication ->>+ B: B.contextPrepared()
    B ->>+ C: ApplicationContextInitializedEvent
    C -->>- B: 
    B -->>- SpringApplication: 
    SpringApplication ->>+ B: B.contextLoaded()
    B ->>+ C: ApplicationPreparedEvent
    C -->>- B: 
    B -->>- SpringApplication: 
    SpringApplication ->>+ refresh context: refresh (自动配置、自动注入...)
    refresh context -->>- SpringApplication: 
    SpringApplication ->>+ B: B.started()
    B ->>+ C: ApplicationStartedEvent
    C -->>- B: 
    B -->>- SpringApplication: 
    SpringApplication ->>+ B: B.running()
    B ->>+ C: ApplicationReadyEvent
    C -->>- B: 
    B -->>- SpringApplication: 
    

截屏2020-03-29下午7.06.52

  • A: ApplicationContextInitializer
  • B: SpringApplicationRunListener
  • C: ApplicationListener
  • D: EnviromentPostProcessor
  • E: PropertySourceLoader
  • F: SpringBootExceptionReporter
  • G: FailureAnalyzer
  • H: FailureAnalysisReporter

启动过程的SPI,不包括refreshContext中的SPI。

  • BeanFactoryPostProcessor