Spring Boot

What happens during Spring Boot startup?

Spring Boot startup involves creating the application context, scanning beans, processing auto-configuration, wiring dependencies, initializing the embedded server, and preparing the application to serve requests.

Spring BootSpringDependency InjectionBackendArchitecture

The Short Answer

Spring Boot startup is the process of building the application context, creating beans, wiring dependencies, applying auto-configuration, and starting the embedded server.

The key idea: Spring Boot builds and wires your application before your code starts handling requests.

The Big Picture

Start Application
Build ApplicationContext
Create & Wire Beans
Start Embedded Server
Ready For Requests

From the application developer's perspective, startup may appear as simple as:

java
SpringApplication.run(App.class, args);

But internally, Spring Boot performs a large amount of orchestration before the application becomes ready.

Step 1: Main Method Starts SpringApplication

java
@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

This is the entry point. Spring Boot creates a SpringApplication object and begins the startup lifecycle.

One important thing happens immediately:

java
@SpringBootApplication

This annotation combines:

java
@Configuration
@ComponentScan
@EnableAutoConfiguration

That single annotation is one reason Spring Boot feels so compact.

Step 2: Build the ApplicationContext

The ApplicationContext is the central container that manages Spring beans and dependency injection.

Think of ApplicationContext as:

the giant runtime object graph manager for your application

During startup, Spring Boot creates the ApplicationContext and begins discovering components.

Step 3: Component Scanning

Spring scans packages looking for annotations like:

java
@Component
@Service
@Repository
@Controller
@RestController

These classes become Spring-managed beans.

@Service

Business logic

@Repository

Database access

@RestController

HTTP endpoints

Spring registers metadata about these classes so it can later create and inject them.

Step 4: Dependency Injection

Spring now creates bean instances and wires dependencies together.

java
@Service
public class OrderService {

    private final PaymentService paymentService;

    public OrderService(PaymentService paymentService) {
        this.paymentService = paymentService;
    }
}

Spring sees that OrderService depends on PaymentService and injects the dependency automatically.

This is one of the biggest ideas in Spring: your application code declares dependencies, and the container builds the object graph.

Step 5: Auto-Configuration

This is where Spring Boot becomes different from traditional Spring.

Spring Boot looks at:

  • dependencies on the classpath
  • application.properties / YAML
  • existing beans
  • environment settings

Then it automatically configures common infrastructure.

Dependency Detected

spring-boot-starter-web

Auto Configuration

Configure embedded Tomcat + MVC infrastructure

This is why adding one starter dependency can suddenly enable large amounts of framework behavior.

Step 6: Bean Lifecycle Callbacks

Some beans perform initialization work during startup.

java
@PostConstruct
public void init() {
    System.out.println("Bean initialized");
}

Spring also supports startup hooks like:

java
CommandLineRunner
ApplicationRunner

These run after the context is fully initialized.

Step 7: Embedded Server Startup

If this is a web application, Spring Boot starts the embedded server.

Spring Boot App

Application Context

Embedded Server

Tomcat / Jetty / Undertow

Ready

Listening for HTTP requests

One reason Spring Boot became so popular is that applications became self-contained:

java
java -jar app.jar

No external application server installation required.

Why Startup Can Become Slow

Large Spring applications sometimes have slow startup times because:

  • many beans are created
  • classpath scanning is expensive
  • reflection is used heavily
  • database connections initialize
  • caches warm up
  • large dependency graphs exist
Understanding startup flow helps diagnose slow startup and memory issues in real systems.

The Interview-Friendly Explanation

Spring Boot startup begins with SpringApplication.run(). Spring creates the ApplicationContext, scans for components, creates and wires beans, applies auto-configuration based on dependencies and environment, runs bean lifecycle callbacks, and finally starts the embedded web server so the application can accept requests.

Common Interview Follow-Ups

What does @SpringBootApplication do?

It combines @Configuration, @ComponentScan, and @EnableAutoConfiguration.

What is ApplicationContext?

It is Spring's central container that manages beans, dependency injection, lifecycle, configuration, and application infrastructure.

What is auto-configuration?

Spring Boot automatically configures infrastructure based on classpath dependencies, properties, environment, and existing beans.

Why can startup become slow?

Large applications may have many beans, heavy reflection usage, expensive scanning, database initialization, cache warmup, and large dependency graphs.

What starts first: Tomcat or the ApplicationContext?

The ApplicationContext is initialized first. After the application is sufficiently prepared, Spring Boot starts the embedded server.

Final Takeaway

Spring Boot startup is really the framework constructing your application runtime: discovering components, wiring dependencies, configuring infrastructure, and preparing the system to serve requests.