What is auto-configuration in Spring Boot?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Spring Boot topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

Auto-configuration is Spring Boot's core feature that automatically configures Spring beans based on: (1) Dependencies on the classpath; (2) Existing beans in the application context; (3) Properties defined in application.properties/yaml. How it works: Spring Boot includes over 100 auto-configuration classes annotated with @Configuration. Each uses @Conditional annotations to activate only when specific conditions are met. Example: DataSourceAutoConfiguration fires when spring-jdbc is on the classpath AND no DataSource bean is defined. @SpringBootApplication meta-annotation includes @EnableAutoConfiguration which imports AutoConfigurationImportSelector — reads all auto-configuration class names from META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports and applies conditional ones. Conditional annotations: @ConditionalOnClass(DataSource.class) — active only if DataSource class is on classpath; @ConditionalOnMissingBean(DataSource.class) — active only if no DataSource bean exists (allows override); @ConditionalOnProperty("spring.jpa.enabled"); @ConditionalOnWebApplication. Seeing what's configured: run with --debug flag or spring.boot.admin.server.enabled=true — prints conditions evaluation report. Overriding: define your own bean of the same type → auto-configured bean is disabled. Use @SpringBootTest to test auto-configuration behavior.

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Spring Boot codebase.