Spring Boot Auto-Configuration — How It Works Internally
Fast recall
Quick revision
Core answer
META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (or spring.factories in pre-2.7) for candidate configuration classes. Each candidate is conditionally applied using `@ConditionalOn*` annotations that check for the presence of classes, beans, or properties. This lets Spring Boot configure sensible defaults without requiring explicit XML or Java configuration. There is no scanning, no guessing — every auto-configuration class is a regular @Configuration guarded by conditions; activation is deterministic given the same classpath, properties, and user-defined beans.Whether the candidate understands the mechanism behind Spring Boot's 'magic' rather than just using it as a black box
Saying 'Spring Boot just auto-configures things' without explaining how conditions and the imports file drive the process
Mention the difference between `spring.factories` (pre-2.7) and `AutoConfiguration.imports` (2.7+), and how `@AutoConfigureAfter`/`@AutoConfigureBefore` control ordering
Interview-ready guide
Interview answer
When Spring Boot 'just works' without any configuration, auto-configuration is what is happening behind the scenes. It is not magic — it is conditional bean registration driven by what is on your classpath and what beans you have already defined.
How it is discovered
@SpringBootApplicationincludes@EnableAutoConfiguration, which readsMETA-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports(Spring Boot 2.7+) listing hundreds of candidate auto-configuration classes- Each class is evaluated for its
@Conditionalannotations before any beans are created
How conditions decide what registers
@ConditionalOnClass(HikariDataSource.class)— only apply this config if HikariCP is on the classpath@ConditionalOnMissingBean(DataSource.class)— only apply if you have not already defined aDataSource; this is how your custom bean overrides the default- Your
@Configurationclasses are processed before auto-configuration — auto-config is always the fallback, never the override
Ordering
@AutoConfigureAfter/@AutoConfigureBeforedeclare dependencies between auto-configurations- Without explicit ordering, beans depending on auto-configured collaborators may fail at startup
Debugging
- Add
--debugto the JVM arguments and Spring prints the Conditions Evaluation Report at startup - Three sections: positive matches (auto-config that ran), negative matches (auto-config that was skipped and why), and exclusions
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigurationremoves a class entirely when a starter pulls in something unwanted
In an interview, the strong answer is: auto-configuration is a deterministic pipeline of conditional `@Configuration` classes discovered from a registration file; the same inputs always produce the same context.
Spring Boot Auto-Configuration — How It Works Internally
Direct Answer
Spring Boot auto-configuration uses @EnableAutoConfiguration to scan META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (or spring.factories in pre-2.7) for candidate configuration classes. Each candidate is conditionally applied using @ConditionalOn* annotations that check for the presence of classes, beans, or properties. This lets Spring Boot configure sensible defaults without requiring explicit XML or Java configuration. There is no scanning, no guessing — every auto-configuration class is a regular @Configuration guarded by conditions; activation is deterministic given the same classpath, properties, and user-defined beans.
Common Mistakes & Pitfalls
Saying 'Spring Boot just auto-configures things' without explaining how conditions and the imports file drive the process
Check your understanding
Answer these without looking back at the article.
- How would you debug which auto-configurations are being applied at startup?
- How do you write and register your own auto-configuration for an internal library?
- What is the difference between `@Configuration` and `@AutoConfiguration`?
- Why did Spring Boot 2.7 introduce `AutoConfiguration.imports` instead of continuing with `spring.factories`?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.