Springboot 2 Start-source process

To use a static method SpringApplication.run(Bootstrap.class, args)start Springboot, for example, is divided into SpringApplication start the process of creating and running in two parts;

create

  1. Set resource loader, here is empty
  2. Set Springboot startup class
  3. The web-based route determination, and the default is SERVLET-> Spring MVC
  4. Reading each packet /META-INF/spring.factories jar file, obtaining org.springframework.context.ApplicationContextInitializer key value, i.e. initializer
  5. Reading each packet /META-INF/spring.factories jar file, obtaining org.springframework.context.ApplicationListener key value, i.e. listeners
  6. From the stack elements of the current runtime, locate the class where the main method

run

  1. Start stopwatch
  2. Read /META-INF/spring.factories jar file for each package, to get key value org.springframework.boot.SpringApplicationRunListener, that Springboot run listener, there is a default EventPublishingRunListener
  3. Start the listener, using the event dispatcher to dispatch ApplicationStartingEvent event listeners
  4. According to the command line arguments args initialization DefaultApplicationArguments
  5. Acquisition environment configuration, bound to a Spring application, and distribute ApplicationEnvironmentPreparedEvent event
  6. Configuring spring.beaninfo.ignore designated negligible Bean
  7. Banner Printing
  8. Creating a Context According to web type, the default is AnnotationConfigServletWebServerApplicationContext
  9. Each jar package file read /META-INF/spring.factories acquires org.springframework.boot.SpringBootExceptionReporter key value, i.e., a failure analyzer, there is a default FailureAnalyzers
  10. Preparation context, that it is configured to property, the callback is initialized, and distribute ApplicationPreparedEvent event
  11. Refresh vessel, the creation of Bean, call the refresh () method, see Spring source summary
  12. Processing, empty method subclasses can implement this method to do additional treatment after refresh
  13. Stopwatch, long time to start printing
  14. Distribute ApplicationStartedEvent event
  15. Call ApplicationRunner, CommandLineRunner implementation methods
  16. Distribute ApplicationReadyEvent event
  17. If an exception occurs during startup, distribution ApplicationFailedEvent events, and failed analyzer

The role of some initialization and listeners

Initializer

  1. DelegatingApplicationContextInitializer: acquiring environment configuration context.initializer.classes designated initializer.
  2. ContextIdApplicationContextInitializer:初始化 Spring 应用名 ID:profile:PORT。(spring.application.name:spring.profiles.active:spring.application.name)
  3. ConfigurationWarningsApplicationContextInitializer: Check the initial configuration, outputting warning log.
  4. ServerPortInfoApplicationContextInitializer: initialize listening to WebServerInitializedEvent event, add a listener to the dispatcher
  5. SharedMetadataReaderFactoryContextInitializer: Initialization and cache metadata read postprocessor CachingMetadataReaderFactoryPostProcessor.

Monitor

  1. ConfigFileApplicationListener: loading a configuration file in the default path.
  2. AnsiOutputApplicationListener: listening spring.output.ansi.enabled is configured color output log. always: Color output; ever disable color output; detect :( default) automatic detection.
  3. LoggingApplicationListener: Configure logging system.
  4. ClasspathLoggingApplicationListener: print program started and start the debug log failure of the classpath.
  5. BackgroundPreinitializer: a background thread from trigger early initialization, comprising validator, the message converter or the like. (MessageConverterInitializer, MBeanFactoryInitializer, ValidationInitializer, JacksonInitializer, ConversionServiceInitializer)
  6. DelegatingApplicationListener: acquiring environment configuration context.listener.classes specified listener
  7. ParentContextCloserApplicationListener: If the parent is closed, then close the application context. It listens refresh event to get the context, listening to the shutdown event spread.
  8. FileEncodingApplicationListener: If the system files and environment configuration code does not match, then stop the application.
  9. ClearCachesApplicationListener: After loading the context clear the cache.

Guess you like

Origin www.cnblogs.com/bigshark/p/11355655.html