Technical Medium Software Engineer Backend

How does Spring Boot auto-configuration work under the hood?

Practise this question with AI feedback

Record your spoken answer or type your response to receive immediate scoring and STAR improvements.

💡 Suggested Approach & Sample Answer

Entry point: @SpringBootApplication combines @Configuration, @ComponentScan and @EnableAutoConfiguration.

How candidates are found:
- Spring Boot reads the list of auto-configuration classes from META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports inside the starter JARs (older versions used spring.factories).
- Each listed class is a normal @Configuration class, but it is guarded by conditions.

Conditions decide what is applied:
- @ConditionalOnClass: only if a class is on the classpath (for example, Jackson).
- @ConditionalOnMissingBean: only if you haven't defined your own bean, which is why your configuration always wins.
- @ConditionalOnProperty: only if a property is set, such as spring.cache.type.
- @ConditionalOnWebApplication and others narrow it further.

Ordering: @AutoConfigureBefore / @AutoConfigureAfter control dependencies between auto-configurations, and user configuration is processed before auto-configuration.

Debugging: run with --debug or set debug=true to print the conditions evaluation report showing which auto-configurations matched and why others did not. You can exclude one with @SpringBootApplication(exclude = DataSourceAutoConfiguration.class).

🎯 What Interviewers Listen For

How would you answer this in a real interview?

Use our free AI mock practice tool to test your response, analyze speaking pacing, and refine your STAR structure.

🔗 Related Technical Questions