Spring Boot - Auto-configuration

Last Updated : 4 Apr, 2026

Spring Boot Auto-Configuration in Spring Boot is a feature that automatically configures application components based on the dependencies available in the classpath.

  • It automatically creates and configures required beans, services, and settings for the application.
  • It reduces manual configuration and speeds up development.

Why Auto-Configuration is Important

Before Spring Boot, developers had to manually configure many components in Spring applications.

Example tasks developers had to configure manually:

  • Configure DispatcherServlet
  • Configure view resolvers
  • Configure database connection
  • Configure transaction management
  • Configure embedded server

Spring Boot solves this problem using Auto-Configuration.

How Auto-Configuration Works

Auto-configuration works using the @EnableAutoConfiguration annotation. This annotation tells Spring Boot to automatically configure beans based on:

  • Dependencies in the classpath
  • Application properties
  • Existing beans in the application context
Auto
Auto-Configuration

In most applications, developers use @SpringBootApplication, which internally includes:

  • @Configuration
  • @EnableAutoConfiguration
  • @ComponentScan
Java
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

So when the application starts, Spring Boot scans the classpath and configures the required beans automatically.

Steps to Implement Auto-Configuration in a Spring Boot

Let us see how auto-configuration works in a simple web application.

Step 1: Create a Spring Boot Project

We can create a Spring Boot project using Spring Initializr and Configure the project with the following settings:

  • Project: Maven
  • Language: Java
  • Spring Boot Version: Latest stable version
  • Group: com.example
  • Artifact: auto-config-demo
  • Packaging: Jar
  • Java Version: 17 or later

Add the following dependency:

  • Spring Boot Starter Web

This dependency automatically includes:

  • Apache Tomcat (embedded server)
  • Spring Web MVC
  • JSON support

Download the project and open it in your IDE such as IntelliJ IDEA, Eclipse IDE, or Spring Tool Suite.

Step 2: Project Structure

After importing the project, the structure will look like:

Str
Directory -Structure

The main class is automatically generated by Spring Boot

Step 3: Main Application Class

The main class contains the @SpringBootApplication annotation which enables Auto-Configuration.

Java
@SpringBootApplication
public class AutoConfigDemoApplication{

    public static void main(String[] args) {
        SpringApplication.run(AutoConfigDemoApplication.class, args);
    }

}

Step 4: Create a Controller

Create a controller class inside the same package.

Java
@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello Spring Boot Auto Configuration";
    }

}

Step 5: Run the Application

Run the main class AutoConfigDemoApplication.

Str
output

Spring Boot automatically performs the following configurations:

  • Starts embedded Apache Tomcat
  • Configures DispatcherServlet
  • Enables Spring Web MVC
  • Configures request mapping and JSON converters

We do not need to manually configure:

  • Web server
  • Servlet configuration
  • MVC configuration

Step 6: Test the Application

Open a browser and visit:

http://localhost:8080/hello

Output:

ou
output


Comment