The @EnableAutoConfiguration annotation tells Spring Boot to configure our application automatically. Spring Boot looks at the jar files (libraries) on the classpath and decides which beans and settings our application needs. For example, if Spring MVC and an embedded Tomcat server are on the classpath, Spring Boot assumes we are building a web application and sets up everything needed to run it.
Our own beans still work as usual. We can define them with @Bean methods in a @Configuration class. Auto-configuration adds more beans on top of them. If we define a bean of our own, Spring Boot usually "backs off" and does not create its own bean of the same kind.
The jar files are usually supplied by starter dependencies, but this is not required. Starters and auto-configuration are two separate features, and neither one depends on the other.
Exclude specific auto-configuration classes such that they will never be applied.
2
Exclude specific auto-configuration class names such that they will never be applied.
(Since 1.3.0)
Here is what each meta annotation on @EnableAutoConfiguration does:
@Documented: This is a standard Java annotation. It makes @EnableAutoConfiguration appear in the generated Javadoc of any class that uses it. It has no effect at runtime.
@Inherited: This is also a standard Java annotation. If a class is annotated with @EnableAutoConfiguration, its subclasses are treated as if they have the annotation too. This works only for class inheritance, not for interfaces.
@AutoConfigurationPackage: This registers the package of the annotated class as the "auto-configuration package". Other auto-configurations use this package as the default place to search. For example, Spring Data JPA looks there for @Entity classes and repository interfaces. This is why the main class is usually placed in the root package of the application.
@Import(AutoConfigurationImportSelector.class): This is the part that does the main work. The selector reads the list of available auto-configuration classes, removes the ones we excluded with exclude or excludeName, and removes the ones whose conditions (like @ConditionalOnClass) are not met. It runs after our own configuration classes are processed. That is why Spring Boot can "back off" when we define our own bean.
Example
In this example we use the Spring MVC starter. It adds Spring MVC and Tomcat to the classpath. Because of these libraries, auto-configuration assumes we are building a web application and sets up Spring for us.
The starter is called spring-boot-starter-webmvc in Spring Boot 4 and later. In older versions it was called spring-boot-starter-web (see the version history at the end of this tutorial).
plugins {
java
id("org.springframework.boot") version "4.1.2"
id("io.spring.dependency-management") version "1.1.7"
}
println(">>> EXECUTING SCRIPT: build.gradle.kts (Kotlin DSL)")
group = "com.logicbig.example"
version = "1.0-SNAPSHOT"
java {
sourceCompatibility = JavaVersion.VERSION_25
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
}
plugins {
id 'java'
id 'org.springframework.boot' version '4.1.2'
id 'io.spring.dependency-management' version '1.1.7'
}
println ">>> EXECUTING SCRIPT: build.gradle (Groovy DSL)"
group = 'com.logicbig.example'
version = '1.0-SNAPSHOT'
java {
sourceCompatibility = JavaVersion.VERSION_25
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
The spring-boot-starter-parent sets the versions of all Spring Boot dependencies, so we do not write a version for the starter.
Gradle has no parent POM. Instead, the org.springframework.boot plugin and the io.spring.dependency-management plugin do the same job: they manage the dependency versions for us. The Spring Boot plugin also adds the bootRun task, so we can start the application with gradle bootRun.
Java Classes
package com.logicbig.example;
public class MyBean {
public String getMessage () {
return "a message from MyBean";
}
}
package com.logicbig.example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyWebController {
@Autowired
private MyBean myBean;
@RequestMapping("/")
@ResponseBody
public String theHandler () {
return myBean.getMessage();
}
}
package com.logicbig.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
@EnableAutoConfiguration
public class EnabledAutoConfigExample {
@Bean
public MyBean myBean () {
return new MyBean();
}
@Bean
public MyWebController controller () {
return new MyWebController();
}
public static void main (String[] args) {
SpringApplication.run(EnabledAutoConfigExample.class, args);
}
}
A few things to notice:
We do not create a servlet container, a DispatcherServlet or any web configuration ourselves. Auto-configuration does all of that because it finds Spring MVC and Tomcat on the classpath.
The class EnabledAutoConfigExample has no @Configuration annotation, so Spring treats its @Bean methods in "lite mode". Lite mode is how Spring processes @Bean methods when the declaring class is not CGLIB-proxied. It also applies when proxyBeanMethods is set to false (for example @SpringBootConfiguration(proxyBeanMethods = false)).
Running the example
To run Spring Boot application you can run your main class from IDE, or execute it from the command line using your build tool:
2026-11-03T09:10:48.274-06:00 INFO 21460 --- [ main] c.l.example.EnabledAutoConfigExample : Starting EnabledAutoConfigExample using Java 25 with PID 21460 (D:\LogicBig\example-projects\spring-boot\spring-enable-auto-config\target\classes started by joe2 in D:\LogicBig\example-projects\spring-boot\spring-enable-auto-config) 2026-11-03T09:10:48.278-06:00 INFO 21460 --- [ main] c.l.example.EnabledAutoConfigExample : No active profile set, falling back to 1 default profile: "default" 2026-11-03T09:10:48.851-06:00 INFO 21460 --- [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http) 2026-11-03T09:10:48.862-06:00 INFO 21460 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2026-11-03T09:10:48.862-06:00 INFO 21460 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/11.0.27] 2026-11-03T09:10:48.899-06:00 INFO 21460 --- [ main] b.w.c.s.WebApplicationContextInitializer : Root WebApplicationContext: initialization completed in 599 ms 2026-11-03T09:10:49.159-06:00 INFO 21460 --- [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/' 2026-11-03T09:10:49.164-06:00 INFO 21460 --- [ main] c.l.example.EnabledAutoConfigExample : Started EnabledAutoConfigExample in 1.203 seconds (process running for 1.489)
Accessing http://localhost:8080
Output
$ curl -s "http://localhost:8080" a message from MyBean
See what was auto-configured
To see which auto-configurations were applied (and which were not, and why), start the application with the --debug option. Spring Boot then prints a "conditions evaluation report" in the console.
If we do not want a particular auto-configuration, we can exclude it, for example: @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class).
In real projects we usually write @SpringBootApplication instead of @EnableAutoConfiguration. It includes @EnableAutoConfiguration, plus @Configuration and component scanning. In the next tutorial we will see how to do component scanning with @EnableAutoConfiguration.
Example Project
Dependencies and Technologies Used:
Spring Boot 4.1.2 Corresponding Spring Framework Version 7.0.10 Version Compatibility: 2.0.0.RELEASE - 4.1.2Version List
×
Version compatibilities of spring-boot-starter-parent with this example:
2.0.0.RELEASE
2.0.1.RELEASE
2.0.2.RELEASE
2.0.3.RELEASE
2.0.4.RELEASE
2.0.5.RELEASE
2.0.6.RELEASE
2.0.7.RELEASE
2.0.8.RELEASE
2.0.9.RELEASE
2.1.0.RELEASE
2.1.1.RELEASE
2.1.2.RELEASE
2.1.3.RELEASE
2.1.4.RELEASE
2.1.5.RELEASE
2.1.6.RELEASE
2.1.7.RELEASE
2.1.8.RELEASE
2.1.9.RELEASE
2.1.10.RELEASE
2.1.11.RELEASE
2.1.12.RELEASE
2.1.13.RELEASE
2.1.14.RELEASE
2.1.15.RELEASE
2.1.16.RELEASE
2.1.17.RELEASE
2.1.18.RELEASE
2.2.0.RELEASE
2.2.1.RELEASE
2.2.2.RELEASE
2.2.3.RELEASE
2.2.4.RELEASE
2.2.5.RELEASE
2.2.6.RELEASE
2.2.7.RELEASE
2.2.8.RELEASE
2.2.9.RELEASE
2.2.10.RELEASE
2.2.11.RELEASE
2.2.12.RELEASE
2.2.13.RELEASE
2.3.0.RELEASE
2.3.1.RELEASE
2.3.2.RELEASE
2.3.3.RELEASE
2.3.4.RELEASE
2.3.5.RELEASE
2.3.6.RELEASE
2.3.7.RELEASE
2.3.8.RELEASE
2.3.9.RELEASE
2.3.10.RELEASE
2.3.11.RELEASE
2.3.12.RELEASE
2.4.0
2.4.1
2.4.2
2.4.3
2.4.4
2.4.5
2.4.6
2.4.7
2.4.8
2.4.9
2.4.10
2.4.11
2.4.12
2.4.13
2.5.0
2.5.1
2.5.2
2.5.3
2.5.4
2.5.5
2.5.6
2.5.7
2.5.8
2.5.9
2.5.10
2.5.11
2.5.12
2.5.13
2.5.14
2.5.15
2.6.0
2.6.1
2.6.2
2.6.3
2.6.4
2.6.5
2.6.6
2.6.7
2.6.8
2.6.9
2.6.10
2.6.11
2.6.12
2.6.13
2.6.14
2.6.15
2.7.0
2.7.1
2.7.2
2.7.3
2.7.4
2.7.5
2.7.6
2.7.7
2.7.8
2.7.9
2.7.10
2.7.11
2.7.12
2.7.13
2.7.14
2.7.15
2.7.16
2.7.17
2.7.18
Java 17 min
3.0.0
3.0.1
3.0.2
3.0.3
3.0.4
3.0.5
3.0.6
3.0.7
3.0.8
3.0.9
3.0.10
3.0.11
3.0.12
3.0.13
3.1.0
3.1.1
3.1.2
3.1.3
3.1.4
3.1.5
3.1.6
3.1.7
3.1.8
3.1.9
3.1.10
3.1.11
3.1.12
3.2.0
3.2.1
3.2.2
3.2.3
3.2.4
3.2.5
3.2.6
3.2.7
3.2.8
3.2.9
3.2.10
3.2.11
3.2.12
3.3.0
3.3.1
3.3.2
3.3.3
3.3.4
3.3.5
3.3.6
3.3.7
3.3.8
3.3.9
3.3.10
3.3.11
3.3.12
3.3.13
3.4.0
3.4.1
3.4.2
3.4.3
3.4.4
3.4.5
3.4.6
3.4.7
3.4.8
3.4.9
3.4.10
3.4.11
3.4.12
3.4.13
3.5.0
3.5.1
3.5.2
3.5.3
3.5.4
3.5.5
3.5.6
3.5.7
3.5.8
3.5.9
3.5.10
3.5.11
3.5.12
3.5.13
3.5.14
3.5.15
3.5.16
4.0.0
4.0.1
4.0.2
4.0.3
4.0.4
4.0.5
4.0.6
4.0.7
4.0.8
4.0.9
4.1.0
4.1.1
4.1.2
Versions in green have been tested.
spring-boot-starter-web (Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container (deprecated in favor of spring-boot-starter-webmvc))