Quick revision
The short answer
@SpringBootApplication includes @EnableAutoConfiguration, which imports AutoConfigurationImportSelector, a DeferredImportSelector. Because it is deferred, it runs only after all of our own configuration has been processed. It reads the candidate class names from META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports files on the classpath, removes exclusions, filters out candidates whose conditions cannot match, sorts the rest by their before and after rules, and imports them, where each one's conditions decide which beans it adds.
What to remember
In this answer, we followed auto-configuration from @SpringBootApplication to the final beans. @EnableAutoConfiguration imports AutoConfigurationImportSelector, a DeferredImportSelector that runs after our own configuration so conditions can see our beans. It reads candidates from the AutoConfiguration.imports files, which replaced spring.factories for this in Boot 3, removes exclusions, filters cheaply with build-time metadata, sorts by before and after rules, and imports what remains, where full conditions decide the beans. The condition report explains every decision, and Boot 4 keeps the mechanism while splitting auto-configuration into technology modules.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
@SpringBootApplication includes @EnableAutoConfiguration, which imports AutoConfigurationImportSelector, a DeferredImportSelector. Because it is deferred, it runs only after all of our own configuration has been processed. It reads the candidate class names from META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports files on the classpath, removes exclusions, filters out candidates whose conditions cannot match, sorts the rest by their before and after rules, and imports them, where each one's conditions decide which beans it adds.
Why this question is asked
Auto-configuration feels like magic until something goes wrong: a bean we expected is missing, or Boot creates one we did not want. Interviewers ask how it is found and loaded because the answer explains exactly how to debug and override it. In this answer, we will recap what an auto-configuration class is, follow the loading process step by step from @SpringBootApplication to the final beans, see why the deferred selector matters, and look at how exclusions, ordering and conditions shape the result, including what changes with Spring Boot 4's smaller modules.
1A Quick Recap of Auto-Configuration
An auto-configuration class is an ordinary configuration class, annotated with @AutoConfiguration, whose beans are guarded by conditions. A condition is a check that must pass before Spring registers a bean or processes a class: @ConditionalOnClass checks whether a class is on the classpath, @ConditionalOnMissingBean checks that we have not defined our own bean of that type, and @ConditionalOnProperty checks a configuration property.
So DataSourceAutoConfiguration says, in effect, if a JDBC driver and a connection pool are on the classpath and the application has not defined a DataSource, create one from the spring.datasource properties. Our job is only to put the right starters on the classpath. The interesting part is how Boot finds these classes in the first place.
2@EnableAutoConfiguration Imports a Deferred Selector
@SpringBootApplication is a shortcut for three annotations: @SpringBootConfiguration, @ComponentScan and @EnableAutoConfiguration. The last one is annotated with @Import(AutoConfigurationImportSelector.class).
AutoConfigurationImportSelector implements DeferredImportSelector. An ordinary ImportSelector runs as soon as Spring meets the @Import. A deferred one is held back until every other configuration class, including everything component scanning found, has been parsed. The reason is the conditions: @ConditionalOnMissingBean(DataSource.class) can only give the right answer if our own DataSource definition is already known. If auto-configuration ran first, Boot would create its DataSource and then ours would clash with it. Deferring the import is what lets our definitions win.
3Reading the Candidate List
When the deferred selector finally runs, it loads the list of candidate classes. Since Spring Boot 3.0, every jar that contributes auto-configuration lists its classes in a plain text file, one fully qualified name per line.
In Spring Boot 2, these names lived in META-INF/spring.factories under the EnableAutoConfiguration key. That format was deprecated for auto-configuration in 2.7 and is no longer read for it since 3.0, so a library that only lists its classes in spring.factories is silently ignored by Boot 3. This is one of the most common surprises when upgrading an internal starter.
4Exclusions, Fast Filtering and Ordering
Next, the selector removes exclusions. These come from the exclude and excludeName attributes of @SpringBootApplication or @EnableAutoConfiguration, and from the spring.autoconfigure.exclude property. Boot checks that each excluded class really is an auto-configuration and fails if it is not, so a typo does not go unnoticed.
Then comes a fast filter. Evaluating every condition on a few hundred classes would mean loading them all, so Boot uses precomputed metadata generated at build time (a file called spring-autoconfigure-metadata.properties) to apply the cheap conditions, mainly @ConditionalOnClass, @ConditionalOnBean and @ConditionalOnWebApplication, without loading the classes. Typically most candidates are discarded here, because their libraries are not on the classpath.
Finally, the survivors are sorted. @AutoConfiguration(before = ..., after = ...) and the older @AutoConfigureBefore, @AutoConfigureAfter and @AutoConfigureOrder define the order. Ordering matters because a condition such as @ConditionalOnBean(DataSource.class) in a JPA configuration only works if the DataSource configuration was processed first.
- Process user configurationcomponent scan,
@Beanmethods, regular@Import - Run AutoConfigurationImportSelectordeferred: user beans are already defined
- Load candidates
AutoConfiguration.importsfiles on the classpath - Remove exclusionsexclude,
excludeName,spring.autoconfigure.exclude - Fast filter with metadataclass and web-app conditions without loading classes
- Sortbefore, after and order rules
- Import each classits full conditions decide which beans are added
7 steps in order. Play them, or step through them one at a time.
Our configuration is processed first, so @ConditionalOnMissingBean sees our beans and backs off.
5Conditions Decide the Final Beans
Each remaining class is imported like any configuration class, and now its full conditions are evaluated, on the class and on each @Bean method. This is where @ConditionalOnMissingBean backs off when we defined our own bean, and where @ConditionalOnProperty reads our settings. Boot records every decision in the condition evaluation report.
With the Actuator, the same report is available at /actuator/conditions. When a bean is missing or unexpected, this report is the first place to look, because it says which condition matched or failed and why.
6What Changes With Spring Boot 4
Spring Boot 4 splits the large spring-boot-autoconfigure jar into smaller technology modules, so that auto-configuration for JDBC, web MVC, Jackson and so on lives in its own module, usually pulled in by the matching starter. The loading mechanism described above stays the same, but two practical things change. First, a dependency that used to be enough to trigger an auto-configuration may now need a specific starter or module, so check which starter brings which module after upgrading. Second, some auto-configuration classes moved to new packages, which matters if we exclude them by name or order our own classes relative to them. Check the migration guide for your version rather than assuming the old class names.
7Follow-up questions
Why can't I just use @ConditionalOnMissingBean in my own regular @Configuration class?
We can, but it is unreliable there. Regular configuration classes are processed in an order that depends on scanning and imports, so the bean the condition checks for may not be defined yet. Auto-configuration classes are safe because the deferred selector processes them after all user configuration, and in a defined order among themselves.
How do I write an auto-configuration for an internal library?
Write a class annotated with @AutoConfiguration, guard its beans with conditions such as @ConditionalOnMissingBean so applications can override them, and list the class in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. It should not be in a package that applications component-scan, or it would be loaded as ordinary configuration and lose the deferred ordering.
What is the difference between exclude and a property that disables a feature?
Exclusion removes the whole auto-configuration class before its conditions are checked. Many auto-configurations also offer a property, such as one ending in .enabled, that a condition reads; that switches off part of the feature while keeping the rest. Exclusion is coarser but certain.
8Conclusion
In this answer, we followed auto-configuration from @SpringBootApplication to the final beans. @EnableAutoConfiguration imports AutoConfigurationImportSelector, a DeferredImportSelector that runs after our own configuration so conditions can see our beans. It reads candidates from the AutoConfiguration.imports files, which replaced spring.factories for this in Boot 3, removes exclusions, filters cheaply with build-time metadata, sorts by before and after rules, and imports what remains, where full conditions decide the beans. The condition report explains every decision, and Boot 4 keeps the mechanism while splitting auto-configuration into technology modules.
Open with
@SpringBootApplication includes @EnableAutoConfiguration, and that annotation imports AutoConfigurationImportSelector, which is a DeferredImportSelector. Deferred means Spring holds it back until all of our own configuration classes and scanned components have been processed.
Then, if they want more
That ordering is the key idea, because auto-configuration uses conditions like @ConditionalOnMissingBean, and those can only back off correctly if our beans are already defined. When the selector runs, it loads the candidate class names from META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports files in every jar. Since Boot 3, spring.factories is no longer used for this, which is a common upgrade problem for internal starters.
Then it removes exclusions from the annotation or the spring.autoconfigure.exclude property, applies a fast filter using build-time metadata so it can drop classes whose libraries are missing without loading them, and sorts the rest using @AutoConfiguration before and after. Each remaining class is imported, and its full conditions decide which beans are actually created.
To debug it, I run with debug=true or use the Actuator conditions endpoint, which shows each match and the reason. With Spring Boot 4, the mechanism is the same, but auto-configuration is split into smaller technology modules, so I check which starter brings which module and whether class names I exclude have moved.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 4, Spring Boot 2, Spring Boot 3.0
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How does Spring Boot find and load auto-configurations, and how does...": https://scrivio-interview-library.netlify.app/spring-boot/spring-configuration/5876798598/