Quick revision
The short answer
We declare every ordering relationship explicitly with @AutoConfiguration(before = ..., after = ...), naming the Boot or platform auto-configurations we really depend on, rather than relying on numeric @AutoConfigureOrder values alone. Every class is listed in the AutoConfiguration.imports file and never reached by component scanning. Because naming Boot classes ties us to their names, and Boot 4 moved many of them into new modules and packages, we check those names on every major upgrade, run an ApplicationContextRunner suite against each supported Boot line in CI, and keep the number of platform auto-configurations small enough that the ordering stays understandable.
What to remember
In this answer, we saw how Boot sorts auto-configurations, chose explicit before and after relationships over fragile numbers, registered every class in the imports file outside scanned packages, guarded against Boot 4's renamed classes with Class references or dual names checked by a test, ran ApplicationContextRunner suites on every supported Boot line, and kept the platform small enough to reason about.
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.
We declare every ordering relationship explicitly with @AutoConfiguration(before = ..., after = ...), naming the Boot or platform auto-configurations we really depend on, rather than relying on numeric @AutoConfigureOrder values alone. Every class is listed in the AutoConfiguration.imports file and never reached by component scanning. Because naming Boot classes ties us to their names, and Boot 4 moved many of them into new modules and packages, we check those names on every major upgrade, run an ApplicationContextRunner suite against each supported Boot line in CI, and keep the number of platform auto-configurations small enough that the ordering stays understandable.
Why this question is asked
A shared jar in 150 services turns a small ordering mistake into an estate-wide incident. If a platform auto-configuration that registers a metrics filter runs before the one that creates the web server factory, or a conditional bean is checked before the bean it waits for exists, the platform behaves differently depending on which other starters each service happens to include. Interviewers ask this design question to see whether we understand how Boot orders auto-configurations and how to keep that order stable through upgrades we do not control. In this answer, we will recap how ordering works, choose between relative and numeric ordering, register the classes correctly, protect against Boot's own renames, test across Boot lines, and keep the design small.
1A Quick Recap: How Boot Orders Auto-Configurations
After Boot has collected and filtered its candidates, AutoConfigurationSorter puts them in order. It starts with alphabetical order by class name, so the result is deterministic. Then it applies @AutoConfigureOrder, a number where lower runs earlier. Finally it applies before and after relationships, which are the strongest rule: if A says after = B, B is processed first no matter what the names or numbers say.
Order matters because conditions that look at beans, @ConditionalOnBean and @ConditionalOnMissingBean, only see bean definitions registered by configurations processed earlier. It also decides which of two configurations that both offer a bean of the same type gets there first.
- Alphabetical by class namestable starting point
- Apply @AutoConfigureOrderlower numbers first; default 0
- Apply before and afteralways wins; a cycle fails startup
- Process in final orderbean conditions see earlier beans only
4 steps in order. Play them, or step through them one at a time.
2Relative Ordering, Not Numbers
Numeric order says run me early or late, but not relative to what. If a platform class uses @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE + 10), whether it runs before DataSourceAutoConfiguration depends on the numbers of every other class, including ones from libraries added later. That is fragile: a new starter in one service can change the outcome.
Relative ordering states the real dependency. If our audit auto-configuration needs the DataSource and the ObjectMapper, it says so, and the sorter guarantees it however many other classes appear.
The rule for the platform is that every @ConditionalOnBean or @ConditionalOnMissingBean on a type that another auto-configuration defines must come with an after on that auto-configuration. Numeric order is reserved for the rare case of wanting to be first or last among everything, and even then it is documented.
3Register Correctly and Never Scan
Each platform auto-configuration is listed in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports in the shared jar. That is the only way it enters the sorted list. If a service component-scans the platform package, which happens when the platform package is a parent of the service's package, the classes are registered as ordinary configuration, alongside the application's own, and all the before and after declarations are ignored.
So platform auto-configurations live in a package such as com.example.platform.autoconfigure, outside every service's base package, and a small architecture test in the platform build fails if any class with @AutoConfiguration is not listed in the imports file or is in a package services scan.
4Protecting Against Boot's Own Renames
Referencing Boot's classes in after = ... ties us to their exact names and packages. Usually that is stable, but Boot 4 modularised its auto-configuration, moving many classes into separate modules with new packages. For example, DataSourceAutoConfiguration moved from org.springframework.boot.autoconfigure.jdbc to the spring-boot-jdbc module (package org.springframework.boot.jdbc.autoconfigure; check your version).
With a Class reference, the old name fails to compile against Boot 4, which is actually helpful. With afterName, a string, the old name compiles and the ordering is silently dropped, because the sorter ignores names that are not candidates. So the platform uses Class references where the class is a hard dependency, and when it must support two Boot lines whose names differ, it lists both names in afterName and a test asserts that at least one of them resolves.
5Test the Ordering on Every Supported Boot Line
ApplicationContextRunner builds a small context with the auto-configurations we pass to AutoConfigurations.of(...), and AutoConfigurations sorts them with the same rules Boot uses. So a test can include Boot's real auto-configurations together with ours and assert the outcome that depends on ordering: the conditional bean exists, the user's bean still wins, and a disabled feature stays disabled.
| Boot line | Context runner suite | Reference service |
|---|---|---|
| 3.5.x | required | required |
| 4.0.x | required | required |
| next milestone | allowed to fail, reported | optional |
CI runs this suite in a build matrix, once per supported Boot line, for example the current 3.5 release and 4.0, by overriding the Boot BOM version. A Boot release candidate can be added to the matrix early, so renames and changed defaults are found before the release, not by 150 teams after it. One consuming reference service with a @SpringBootTest, on each line, catches what the slice tests miss.
6Keep the Number Small
Every auto-configuration adds conditions and ordering edges, and the interactions grow faster than the count. With five platform auto-configurations, a person can hold the dependency graph in their head; with forty, nobody can, and the before and after declarations start forming long chains that are hard to change. So the platform groups related beans into a few auto-configurations by feature (observability, security, data, messaging), uses nested configuration classes inside them for optional parts, and documents the graph in the platform's README with the reason for each edge.
7Follow-up questions
What happens if two auto-configurations declare before and after on each other?
That is a cycle, and AutoConfigurationSorter fails startup with an error naming the classes involved. ApplicationContextRunner tests reveal it immediately, which is another reason to test the platform classes together.
Should platform auto-configurations run before or after Boot's?
Usually after the Boot configurations whose beans they use, and before any Boot configuration that should back off because of them. If a platform class provides a default ObjectMapper customizer, it does not need ordering at all; if it provides a replacement bean that Boot should back off for, it must say before the Boot class.
Why not let services order platform pieces themselves?
Because services would need to know platform internals, and 150 teams would make 150 choices. Ordering is a property of the platform's own design; services should only toggle features with properties.
8Conclusion
In this answer, we saw how Boot sorts auto-configurations, chose explicit before and after relationships over fragile numbers, registered every class in the imports file outside scanned packages, guarded against Boot 4's renamed classes with Class references or dual names checked by a test, ran ApplicationContextRunner suites on every supported Boot line, and kept the platform small enough to reason about.
Open with
I'd order everything with explicit relationships. Boot sorts candidates alphabetically, then by @AutoConfigureOrder, and then applies before and after, which always win, so I'd use @AutoConfiguration(after = ...) for every Boot or platform auto-configuration whose beans we read or condition on, and before for any that should back off because of us.
Then, if they want more
I'd avoid numeric orders, because whether a number puts us before DataSourceAutoConfiguration depends on every other class on the classpath. Every class goes into the AutoConfiguration.imports file in the shared jar, in a package no service scans, with an architecture test that enforces both, because component scanning would ignore the ordering entirely.
Referencing Boot classes ties us to their names, and Boot 4 moved many auto-configurations into new modules and packages. A Class reference breaks the build on a rename, which is good; a string afterName silently drops the ordering, so where I need to support Boot 3.5 and 4 from one jar I'd list both names and test that one resolves.
Then CI runs an ApplicationContextRunner suite with our classes and the real Boot auto-configurations, asserting beans that depend on order, on every supported Boot line, plus a reference service. And I'd keep the number of platform auto-configurations small, grouped by feature, so the ordering graph stays understandable.
About this answer
- Last updated
- 12 November 2026
- 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 Boot reference
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 "Your platform ships internal auto-configurations in a shared jar used by 150 services....": https://scrivio-interview-library.netlify.app/spring-boot/auto-configuration/81b108b19b/