Quick revision
The short answer
I would print the condition evaluation report, look at the positive matches for features the service never uses, and remove the dependency that pulls each one in, using exclusions only when the dependency has to stay. Before and after, I would measure startup with the startup actuator endpoint or JFR, because the 450 candidates themselves are usually cheap and the real seconds are often spent in a few heavy beans such as the JPA setup, connection pools and remote calls.
What to remember
In this answer, we saw that the condition evaluation report shows which auto-configurations matched and why, and that the positive matches point to features the service may not use. We remove the dependency that brings each unused feature in, and exclude the configuration only when the jar must stay. We measure before and after with the startup endpoint or JFR, because the large candidate count is usually cheap, and the real cost tends to sit in a few heavy beans such as the JPA metamodel, connection pools, migrations and remote calls.
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.
I would print the condition evaluation report, look at the positive matches for features the service never uses, and remove the dependency that pulls each one in, using exclusions only when the dependency has to stay. Before and after, I would measure startup with the startup actuator endpoint or JFR, because the 450 candidates themselves are usually cheap and the real seconds are often spent in a few heavy beans such as the JPA setup, connection pools and remote calls.
Why this question is asked
A slow-starting service hurts more than it used to. Every rollout, every autoscaling event and every local restart pays the 25 seconds. A large number like 450 auto-configuration candidates looks like the obvious culprit, and interviewers ask this question to see whether we trim with evidence or by guessing. In this answer, we will recap what the condition evaluation report shows, read it to find configurations the service does not need, remove them the right way, and then measure, because the real cost is often somewhere else.
1A Quick Recap of Auto-configuration Candidates
Spring Boot ships hundreds of auto-configuration classes, ordinary @Configuration classes marked with @AutoConfiguration, each guarded by conditions such as @ConditionalOnClass (only if a class is on the classpath) or @ConditionalOnMissingBean (only if we have not defined that bean ourselves). At startup Boot reads the list of candidates from the META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports files of every jar, which is how a count like 450 appears once libraries add their own.
Each candidate is evaluated. If its conditions pass, it is a positive match and its beans are created. If a condition fails, it is a negative match and the class is skipped, often without even being loaded fully, because Boot checks many class conditions from precomputed metadata. So a negative match costs very little. A positive match costs whatever its beans cost to create, and that is where startup time can go.
2Reading the Condition Evaluation Report
The condition evaluation report lists every candidate and why it matched or did not. We can get it by starting the service with the --debug flag or debug=true, or from a running service through the conditions actuator endpoint.
Notice that the useful part is the positive matches. In this made-up orders service, the team uses PostgreSQL only, yet MongoDB and Redis configurations matched. They matched because the Mongo driver and Lettuce are on the classpath, probably brought in by a shared library or an old experiment. Those configurations create clients, connection factories and health indicators, and the Mongo client may even try to connect in the background. The negative matches, by contrast, are mostly noise for this question.
3Removing the Dependency Instead of Excluding the Class
Once we know MongoDB is unused, we have two choices. We can exclude MongoDataAutoConfiguration and MongoAutoConfiguration, or we can remove the dependency that put the Mongo driver on the classpath. Removing the dependency is better. The reason is that an exclusion only silences one configuration class, while the jar stays in the image, still adds classes to scan, still shows up in vulnerability reports, and can be picked up by another auto-configuration that also checks for it.
When the dependency must stay, for example because a library we need has a hard dependency on Lettuce but we never want a Redis connection, we exclude the auto-configuration instead, either with @SpringBootApplication(exclude = RedisAutoConfiguration.class) or with the spring.autoconfigure.exclude property. That is the right tool for the remaining cases, not the first one.
4Measuring Before and After
Here is the catch: removing ten unused configurations may save half a second. If the service still takes 24 seconds, we trimmed the wrong thing. So before changing anything, we record where startup time goes. Spring records startup steps when we give the application a BufferingApplicationStartup, and the startup actuator endpoint returns them with their durations. FlightRecorderApplicationStartup records the same steps as JFR events instead.
- Measure startupstartup endpoint or JFR, note total time
- Read positive matchesconditions report
- Is the feature used?YesKeep itNoFind who pulls the jar in
- Can the dependency go?YesRemove it from the buildNoExclude the auto-configuration
- Check the heavy beansJPA, pools, remote calls
- Measure againcompare with the first number
6 steps in order. Play them, or step through them one at a time.
We sort the spring.beans.instantiate steps by duration and look at the top ten. In most slow services the list is short and familiar, and it is rarely the auto-configuration machinery itself.
5Where the Seconds Usually Go
When we look at the slowest beans, a few kinds come up again and again. The JPA EntityManagerFactory builds the Hibernate metamodel for every entity, and with several hundred entities and schema validation turned on (spring.jpa.hibernate.ddl-auto=validate), it reads database metadata too. Connection pools such as HikariCP open their first connections at startup. Clients for other services or a configuration server may make remote calls in their constructors or @PostConstruct methods, and a slow network turns that into seconds. Flyway or Liquibase migrations run before the context is ready. Large classpath scans with broad @ComponentScan packages also add up.
Each has its own fix: turn off schema validation in production or move it to a test, let Hibernate bootstrap in the background with spring.data.jpa.repositories.bootstrap-mode=deferred, move migrations to a separate job, and make remote clients connect lazily. These usually win far more than the trimming of configuration classes, and the first measurement tells us which one applies.
6Follow-up questions
Does the number of auto-configuration candidates itself slow startup much?
Not much. Most candidates fail a class condition that Boot checks cheaply, often from precomputed metadata, before loading the configuration class. The cost comes from the beans that positive matches create. That is why the conditions report is a map for finding unneeded features, while the startup endpoint is the tool for finding the seconds.
Why not just exclude every unused auto-configuration in one long list?
Because the list hides the real problem and has to be maintained. The unused jars stay in the image and in security scans, and a new version of Boot may add a new configuration for the same library that the list does not mention. Removing the dependency fixes the cause; exclusions are for jars we must keep.
How do we stop the unused dependencies from coming back?
We can add the dependency tree or the list of positive matches to the build output and compare it in review, or use a rule such as the Maven Enforcer banned dependencies rule for libraries the service must not carry. A test that starts the context and asserts certain beans are absent also works.
7Conclusion
In this answer, we saw that the condition evaluation report shows which auto-configurations matched and why, and that the positive matches point to features the service may not use. We remove the dependency that brings each unused feature in, and exclude the configuration only when the jar must stay. We measure before and after with the startup endpoint or JFR, because the large candidate count is usually cheap, and the real cost tends to sit in a few heavy beans such as the JPA metamodel, connection pools, migrations and remote calls.
Open with
First I would measure, not guess. I would give the application a BufferingApplicationStartup, expose the startup endpoint, and sort the bean instantiation steps by duration, so I know where the 25 seconds actually go.
Then, if they want more
Then I would run the service with debug enabled or read the conditions endpoint and go through the positive matches, because those are the configurations that actually create beans.
If I see things like MongoDB or Redis matching in a service that only uses PostgreSQL, I would find who pulls those jars in with the dependency tree and remove them from the build.
Removing the dependency is better than excluding the class, because the jar otherwise stays in the image, in the scans and on the classpath for other conditions. I would use spring.autoconfigure.exclude only where the dependency has to stay.
The 450 candidates are mostly cheap negative matches, so I would expect the big wins elsewhere: the Hibernate metamodel and schema validation, the connection pool, Flyway migrations, and clients that make remote calls during startup. I would fix those, for example by moving migrations to a job or using deferred repository bootstrap, and then measure again to confirm the change.
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 "A service on Boot 3 starts with 450 auto-configuration candidates and takes 25 seconds....": https://scrivio-interview-library.netlify.app/spring-boot/auto-configuration/3ad96aaf11/