How Does Spring Application Works?

Initialization of Spring Boot

The initialization of a Spring Boot application involves the following concise steps:

  1. SpringApplication.run(): Entry point that launches the application.
  2. Environment Preparation: Sets up the application environment, including configuration properties and profiles.
  3. Application Context Creation: Creates the ApplicationContext (e.g., AnnotationConfigApplicationContext).
  4. Bean Definition Loading: Scans and registers beans and their dependencies.
  5. Listeners and Initializers: Registers and invokes application listeners and initializers.
  6. Context Refreshing: Instantiates, configures, and wires beans; starts the embedded web server if applicable.
  7. Post-Processing: Executes any CommandLineRunner and ApplicationRunner beans.
  8. Ready State: Publishes the ApplicationReadyEvent signaling the application is ready to handle requests.

What is Spring Container?

The Spring container is a core component of the Spring Framework. It is responsible creating and managing the lifecycle and configuration of application objects (Beans). The Container reads configuration metadata to know how to initiate, configure, and assemble these beans. This metadata can be supplied in various forms such as XML, annotations, or Java code.

Responsibility of IOC Container

Untitled

Note: To understand more about setting up configuration metadata read this documentation What is Spring IOC Container with Example (javaguides.net)