Skip to main content

Command Palette

Search for a command to run...

Mastering Spring Framework:1.2

Pom.xml,Maven,Spring Boot Auto-Configuration, Internal Working of a Spring Boot Application

Updated
•6 min read•View as Markdown

Introduction

Spring Boot often feels magical.

You add a dependency, write a controller, run the application — and suddenly:

  • A server starts

  • Endpoints work

  • JSON responses appear

  • No XML

  • No manual configuration

This raises important questions:

  • What exactly is pom.xml?

  • What role does Maven play?

  • How does Spring Boot auto-configuration work?

  • What is the ApplicationContext?

  • What happens internally when a Spring Boot application starts?

In this article, we will open the black box and understand the internal working of Spring Boot step by step.

📦 What is pom.xml?

In a Spring Boot project, dependencies are specified in the pom.xml file.It defines the external libraries, frameworks, or other project modules that the current project requires to compile, run, and function correctly

In simple words:

pom.xml tells Maven what libraries your project needs and how to build the project.

🧰 What is Maven?

Maven is a build automation tool and depedency management tool used in Java Projects.

Mavaen resolves dependencies from pom.xml and puts them into the classpath (Classpath is the list of locations (folders + JARs) that the JVM searches to load classes at runtime.)

Maven goes to the internet , finds the libraries , downloads them and puts them into your project automaticcally

What Maven does:

  • Downloads required libraries (JARs)

  • Resolves dependency conflicts

  • Manages versions

  • Builds the project

  • Packages the application (JAR/WAR)

In a Spring Boot project:

  • Dependencies are declared in pom.xml

  • Maven resolves them

  • Maven adds them to the classpath

    🧩 Spring Boot Parent POM (spring-boot-starter-parent)

    In most Spring Boot projects, you’ll see this:

      <parent>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-parent</artifactId>
          <version>3.x.x</version>
      </parent>
    

    This parent POM provides:

    • Default plugin configurations

    • Java version management

    • Dependency version alignment

You don’t need to manually specify versions for most dependencies.


📚 spring-boot-dependencies (Very Important)

Behind the scenes, Spring Boot uses another POM:

spring-boot-dependencies

This POM contains:

  • Every third-party library

  • The exact version Spring Boot supports

All dependencies are defined under <dependencyManagement>.

Why this matters:

  • You don’t specify versions manually

  • No version conflicts

  • Everything is tested to work together

This is one of the biggest reasons Spring Boot feels stable.


🧱 What are Spring Boot Starters?

Spring Boot starters are dependency bundles.

Example:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

This single starter pulls:

  • Spring MVC

  • Tomcat

  • Jackson(Json)

  • Validation libraries

  • Logging

👉 You add one dependency, Maven adds many libraries automatically.

⚙️ What is Spring Boot Auto-Configuration?

Auto-configuration automatically configures your Spring application based on what is present on the classpath.

Auto-configuration checks classpath and automatically setup and creates beans for you based on what libraries are present on the classpath

Instead of you configuring everything manually, Spring Boot:

  • Detects dependencies

  • Applies sensible defaults

  • Creates required beans automatically

This is why Spring Boot reduces boilerplate code.

If you include

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Spring says Ah You are building a web app so it autoconfigures

-Tomacat server

-Dispatcher servlet

-Handler mappings

-JSON converter

-Error controller etc

If you add spring-boot-starter-Data-Jpa then it automatically configures

-EntitiyManagaerFactory

-Hibernate

-Data Source etc

so Autoconfiguration in spring is a smart mom who sees what toys you have and setups up automatically without you asking

you bring cricket bat —> mom finds stumps and a ball immediately

.


🧑‍💻 2. How Does Auto-Configuration Work Internally?

Here is the internal magic:

➤ Step 1 — @SpringBootApplication triggers auto-config

Because of:

@EnableAutoConfiguration

Which says:

“Spring, please load all auto-configuration classes that you find.”


➤ Step 2 — Spring Boot looks inside this file:

META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

This file contains hundreds of auto-config classes like:

  • DataSourceAutoConfiguration

  • HibernateJpaAutoConfiguration

  • WebMvcAutoConfiguration

  • JacksonAutoConfiguration

  • DispatcherServletAutoConfiguration

Spring loads ALL of these classes.


➤ Step 3 — Spring checks conditions

Each auto-config class uses powerful annotations:

  • @ConditionalOnClass

  • @ConditionalOnMissingBean

  • @ConditionalOnProperty

  • @ConditionalOnWebApplication

This lets Spring decide:

“Should I create this bean or not?”


Example:

WebMvcAutoConfiguration is enabled only if:

  • Spring MVC classes exist

  • No custom WebMvcConfiguration is present

So, Spring will auto-create:

  • DispatcherServlet

  • HandlerMapping

  • HandlerAdapters

  • MessageConverters

🧠 How Auto-Configuration Decides What to Configure

Spring Boot uses three main checks:

1️⃣ Classpath Check

Spring Boot asks:

“Is a specific library present?”

Examples:

  • If spring-web is present → configure MVC

  • If spring-data-jpa is present → configure JPA

  • If hibernate is present → configure ORM


2️⃣ Property Check

Spring Boot checks application properties:

spring.datasource.url=jdbc:mysql://localhost:3306/test

If such properties exist, Spring Boot configures:

  • DataSource

  • EntityManager

  • TransactionManager


3️⃣ Bean Check (Back-off mechanism)

Spring Boot asks:

“Has the developer already defined this bean?”

  • If yes → Spring Boot backs off

  • If no → Spring Boot creates it

This ensures developer control.

🧠 What is ApplicationContext?

ApplicationContext is Spring’s IoC container.

It is responsible for:

  • Creating beans

  • Managing bean lifecycle

  • Injecting dependencies

  • Holding application configuration

Think of it as a big container (box) that holds all ready-to-use objects

🔄 Internal Working of a Spring Boot Application

Let’s understand what happens when you run:

SpringApplication.run(DemoApplication.class, args);

1️⃣ JVM Starts

  • main() method executes

2️⃣ SpringApplication is Created

Spring:


3️⃣ ApplicationContext is Created

  • IoC container initializes

  • Bean factory is prepared


4️⃣ Component Scanning

Spring scans for:

  • @Component

  • @Service

  • @Repository

  • @Controller

Beans are created and stored in the container.


5️⃣ Auto-Configuration Runs

Spring Boot:

  • Reads spring.factories

  • Loads auto-configuration classes

  • Applies conditions

  • Creates default beans


6️⃣ Embedded Server Starts

If spring-boot-starter-web is present:

  • Tomcat starts

  • DispatcherServlet is registered

  • Port opens


7️⃣ Application Is Ready 🚀

Your application is now fully running.


🔗 How Maven + Auto-Configuration Work Together

Flow:

  1. You add a dependency in pom.xml

  2. Maven downloads libraries

  3. Libraries go to classpath

  4. Spring Boot scans classpath

  5. Auto-configuration configures beans

👉 Maven provides the libraries
👉 Spring Boot configures them

Without Auto-Configuration — What Would You Have To Do Manually?

This is where you will fully understand the VALUE of autoconfiguration.

Let’s imagine Spring Boot didn’t exist.

Below are things YOU would have to write yourself.


💥 Case 1: Starting a Web Server (No Auto-Config)

Without auto-config, you must manually configure:

❌ Create and configure a Servlet container (Tomcat/Jetty)

You would write:

Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.addWebApp("/", "/src/main/webapp");
tomcat.start();

❌ Register DispatcherServlet manually

DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
tomcat.addServlet("/", "dispatcher", dispatcherServlet);

❌ Manually register HandlerMapping, HandlerAdapter, ViewResolver

Spring MVC components do NOT auto-register.

You must create beans manually:

@Bean
public RequestMappingHandlerMapping handlerMapping() { … }

@Bean
public RequestMappingHandlerAdapter handlerAdapter() { … }

This is a LOT of work.

✔ Autoconfiguration = Spring automatically creates required beans based on classpath + conditions.

✔ Without it, you would need to manually configure:

  • Tomcat

  • DispatcherServlet

  • HandlerMapping

  • HandlerAdapter

  • ViewResolvers

  • DataSource

  • EntityManagerFactory

  • TransactionManager

  • Security filter chain

  • JSON serializers

  • Error handlers

✔ Auto-configuration is what makes Spring Boot easy and fast.

🎯 Conclusion

  • pom.xml defines what your project needs

  • Maven resolves and manages dependencies

  • Spring Boot auto-configuration decides how to configure

  • ApplicationContext manages all beans

  • Conditional logic ensures flexibility

Together, Maven + Spring Boot Auto-Configuration create a powerful, developer-friendly ecosystem.