I Reverse-Engineered Spring Boot - What I Found Will SHOCK You

    I Reverse-Engineered Spring Boot - What I Found Will SHOCK You

    Understand the Internal Working of Spring Boot. Learn how auto-configuration, starter dependencies, embedded servers, and externalized configurations simplify Java development.

    default profile

    Munaf Badarpura

    July 05, 2025

    5 min read

    If you have worked with Spring Boot before, you’ve probably noticed how little setup is required to get things running. You create a project, add a few annotations, maybe change some properties, and boom, your API is live. But this simplicity doesn't happen automatically. Behind the scenes, Spring Boot performs a lot of smart configurations to hide complexity from developers. In this article, I have explained the internal working of Spring Boot in a simple and easy-to-understand way.

    The Core Building Blocks of Spring Boot#

    1. SpringApplication Class#

    This is where every Spring Boot application begins. The SpringApplication.run(...) method might look simple, but it kicks off a chain of powerful behind-the-scenes actions that get your app up and running.

    What It Does:

    @SpringBootApplication public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } }
    • Bootstraps the Spring application.
    • Sets up the ApplicationContext (based on the type of app — web or standalone).
    • Triggers component scanning to register beans and dependencies.
    • Starts the embedded server (Tomcat, Jetty, or Undertow) if it's a web app.
    • Applies auto-configuration based on the dependencies present.
    • Publishes key lifecycle events like ApplicationStartedEvent and ApplicationReadyEvent.
    run() method process

    How It Works:

    When you call SpringApplication.run(...), Spring Boot first prepares the environment by setting up properties and configurations. It then loads all the bean definitions and refreshes the application context. Based on your project type, it decides whether to use AnnotationConfigApplicationContext for a non-web app or WebApplicationContext for a web-based one. After that, auto-configuration kicks in — Spring Boot scans your classpath, detects available libraries, and applies smart defaults accordingly. Finally, if it’s a web application, it starts an embedded server like Tomcat, and your app is ready to serve requests.

    2. @SpringBootApplication Annotation#

    This single annotation is what makes a Spring Boot application tick. It’s actually a meta-annotation that wraps three powerful Spring annotations into one.

    What It Does:

    • @Configuration – Tells Spring that this class contains bean definitions. It’s the starting point for your app’s configuration.
    • @EnableAutoConfiguration – Triggers Spring Boot’s auto-configuration magic based on the dependencies present in your classpath.
    • @ComponentScan – Automatically scans the current package and its subpackages to detect and register components like @Component, @Service, @Repository, and @Controller.

    How It Works:

    When the application starts, Spring sees @SpringBootApplication and uses it to bootstrap the context. It processes all three underlying annotations in one go — registers beans, applies auto-configs, and wires up your components. This reduces boilerplate and makes your app setup clean and minimal with just one annotation.

    3. Auto-Configuration#

    This stands out as the main reason Spring Boot feels so easy to use. it is one of the key features of Spring Boot because it tries to set up your application based on the dependencies you have added in your classpath.

    What It Does:

    • If you add spring-boot-starter-web, Spring Boot automatically sets up an embedded web server (like Tomcat) and gets request handling ready to go.
    • Include spring-boot-starter-data-jpa, and it configures database connections, scans for entities, and sets up repositories—all without you lifting a finger.

    How It Works:

    • Spring Boot scans your classpath to spot libraries and annotations.
    • It matches these against a library of predefined configurations stored in @Configuration classes.
    • These configurations are conditional—they only kick in if certain conditions are met (e.g., the presence of a web starter triggers a Tomcat setup).
    • You can customize or disable this with properties or the exclude attribute if needed.

    4. Spring Boot Starters Dependencies#

    One of the biggest pain points in Spring framework was managing dependencies. Each module (like Spring MVC, Spring Data JPA, or security) required manual dependency management and this often leading to version conflicts and bloated configurations.

    Spring Boot solves this problem with starter dependencies that are predefined sets of dependencies bundled for specific functionalities.

    How It Works:

    • Starters (e.g., spring-boot-starter-webspring-boot-starter-data-jpa) group related dependencies together.
    • Instead of adding individual libraries (like Tomcat, Jackson, Hibernate), you include a single starter.
    • Spring Boot ensures all included libraries versions are compatible with each-other.

    5. Embedded Servers#

    Traditional Java web applications require deploying WAR files to external servers like Tomcat or Jetty But Spring Boot allows you to run your application as a standalone application without needing a separate server.

    How It Works:

    • The spring-boot-starter-web includes an embedded Tomcat server by default.
    • When you include a web starter, During the application startup Spring Boot automatically bundles an embedded Tomcat server.
    • The server is started when the SpringApplication.run() method is called.

    6. Externalized Configuration (properties/yml)#

    Hardcoding configuration details like database passwords, API keys, or server ports directly in your code is risky and inflexible. So Spring Boot fixes this problem with externalized configuration with a way to store settings outside your code, making your app more secure and easier to manage.

    How It Works:

    • You store configurations in application.properties or application.yml files.
    • These can include settings like server ports, database URLs, or logging levels.
    • You can create different profiles (e.g., application-dev.properties for development, application-prod.properties for production) to switch settings based on the environment.

    Here is an example of application.properties file:

    spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=admin spring.datasource.password=secret123

    7. SpringApplication.run() - The Entry Point#

    Every Spring Boot application starts with a main() method calling SpringApplication.run(). But what happens behind this simple line?

    Step-by-Step Breakdown:

    • Execution Begins: Your main() method, usually in a class annotated with @SpringBootApplication, runs and calls SpringApplication.run().
    • Application Context Creation: Spring Boot builds the ApplicationContext, the container that holds all your beans (objects managed by Spring). It scans for annotations like @Component, @Service, or @Repository.
    • Auto-Configuration Applied: Based on your classpath dependencies (e.g., web or JPA starters), Spring Boot applies the right configurations.
    • Embedded Server Startup: If a web starter is present, it starts the embedded server (e.g., Tomcat) and sets it to listen on your configured port (default is 8080).
    • Initialization Complete: Any ApplicationContextInitializer or ApplicationListener beans run to perform custom setup tasks.
    • Application Ready: Once the server is up and the context is fully initialized, your app is live, ready to handle requests.

    Conclusion:#

    Spring Boot simplifies development by handling most of the configurations for you. With features like Auto-Configuration, Starter Dependencies, Embedded Servers and Externalized Configurations helps to build Spring Boot applications fast and hassle-free.

    Want to Master Spring Boot and Land Your Dream Job?

    Struggling with coding interviews? Learn Data Structures & Algorithms (DSA) with our expert-led course. Build strong problem-solving skills, write optimized code, and crack top tech interviews with ease

    Learn more
    Spring Boot
    Internal Working Of Spring Boot
    Spring Boot Interview
    Auto-Configurations

    Subscribe to our newsletter

    Read articles from Coding Shuttle directly inside your inbox. Subscribe to the newsletter, and don't miss out.

    More articles