What is auto configuration in Spring Boot?
Auto configuration is the Spring Boot feature that automatically sets up beans and settings based on the libraries on your classpath. For example, if it finds a database driver, it configures a data source for you. It is triggered by the EnableAutoConfiguration annotation, which the SpringBootApplication annotation includes, and you can always override its defaults.
- Auto configuration sets up beans automatically based on the dependencies on your classpath.
- It uses sensible defaults so you write far less configuration.
- You can override any auto configured bean with your own definition.
How it decides
Spring Boot looks at what is on the classpath and applies matching configuration using conditional checks. If a class is present and you have not defined your own bean, it provides a sensible default one.
@SpringBootApplication // includes @EnableAutoConfiguration
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
You are never locked in. If you define your own bean or set a property, your choice wins over the auto configured default.
Mention that auto configuration is conditional and overridable. Saying it backs off when you provide your own configuration shows you understand it assists you rather than taking control away.
Frequently asked questions
How does Spring Boot know what to configure?
It inspects the classpath and existing beans using conditional annotations, then configures features only when their libraries are present.
How do you disable a specific auto configuration?
You can exclude it, for example with the exclude attribute on EnableAutoConfiguration or SpringBootApplication, when you want full manual control.
Common follow up questions
Related interview questions
Want the full Spring Boot guide?
Read every Spring Boot concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the Spring Boot guide All Spring Boot questions