Scrivio Interview library
Spring Boot21 May 202616 min read

30 Seconds of Nothing: Why Spring Boot's Startup Log Tells You Almost Nothing

You audit every @PostConstruct method. You strip out the ones doing redundant work. You rerun the app, watch the terminal, and see: Started Application in 34.2 seconds. That number is the only thing the log gives you. No breakdown by phase, no indication of which bean took three seconds to initialize, no hint that a single auto-configuration class is pulling in half the internet before your code runs a single line.1

That opacity is the real problem. Most engineers debug slow startup the way they debug slow application code: they look at what they wrote and try to make it leaner. But the majority of Spring Boot's startup time happens in framework territory, before your first @Bean method is even considered. Classpath scanning, auto-configuration resolution, bean definition loading, embedded server initialization, all of it runs in a sequence the framework owns, and none of it appears in the default log.1

Spring Boot's design philosophy is "convention over configuration," which in practice means the framework makes hundreds of decisions on your behalf at startup. It checks which libraries are on the classpath, infers which infrastructure you probably want, and wires it all together without requiring any XML. This is genuinely useful when it works the way you expect. The cost is that every convenience has a corresponding startup action, and those actions accumulate in proportion to how many Spring Boot starters you've included, not how many features your code actually uses.

Think of it like a house where every light in every room switches on when you open the front door. You live in three rooms. The other fourteen are lit anyway. You wouldn't diagnose that problem by inspecting the three rooms you use.

Fixing Spring Boot startup time is an exercise in understanding the framework's phases before you touch your own code. That means learning what auto-configuration actually loads, how the bean factory resolves initialization order, why classpath scanning costs what it does, and which default behaviors you can opt out of without consequences. Each lever exists and is tunable, but none of them are visible until you make the startup process itself observable.

The sections below make those phases visible, starting with a way to turn Spring Boot's opaque startup sequence into something you can actually measure.

The Three Phases That Eat Your Startup Time#

Spring Boot startup is not a single operation. It is three sequential phases, each with its own cost and its own fix. Miss that structure, and you end up tuning the wrong thing: spending an afternoon narrowing component-scan packages when the real drag is a bean hitting a remote API on init.

The three phases are auto-configuration evaluation, bean definition scanning, and bean instantiation. They run in that order, and they are almost entirely invisible in the default startup log.

Phase 1: Auto-Configuration Evaluation. Before Spring even looks at your code, it works through a list of hundreds of candidate auto-configurations bundled with every Spring Boot jar. For each one it evaluates a set of @Conditional checks: is this class on the classpath? Is that property set? Most of these evaluations are fast individually. Collectively, across a full dependency graph, they add up. Spring runs every single check regardless of whether you could ever need the result.2

Phase 2: Bean Definition Scanning. Once Spring knows which configurations are active, it scans the classpath for @Component, @Service, @Repository, and related annotations. This is a filesystem and reflection-heavy operation. At small scale it finishes in milliseconds. In applications with thousands of classes across many jars, the same scan can take one to two minutes, and narrowing basePackages only partially helps because Spring still opens and inspects class files it ultimately rejects.3

Phase 3: Bean Instantiation. With bean definitions in hand, Spring constructs every singleton bean in dependency order. This phase is where wall-clock time can surprise you most, because it hides I/O. A bean whose @PostConstruct method calls a database, fetches a remote configuration, or warms a cache blocks the entire startup sequence. Spring initializes beans one at a time on a single thread by default, so one slow bean delays everything that follows it. A bean querying a European Central Bank web service during init, for example, serializes that latency into your startup time whether you asked for it or not.4

Each phase has a matching lever. Unnecessary auto-configurations are excluded explicitly. Scanning is narrowed or replaced with indexed metadata. Slow bean initialization is deferred or made asynchronous. The sequence diagram below shows the three phases in order.

Diagram as text
sequenceDiagram
 participant JVM
 participant AutoConfig as Auto-Configuration Evaluator
 participant Scanner as Classpath Scanner
 participant Factory as Bean Factory

 JVM->>AutoConfig: Evaluate @Conditional checks for all candidates
 AutoConfig-->>JVM: Active configuration list
 JVM->>Scanner: Scan basePackages for annotated classes
 Scanner-->>JVM: Bean definition registry
 JVM->>Factory: Instantiate singletons in dependency order
 Factory-->>JVM: ApplicationContext ready

The fix for Phase 1 does nothing for Phase 3, and vice versa. Measuring which phase is slow comes first. Everything else follows from that.

Diagram as text
sequenceDiagram
 participant App as "Application"
 participant AutoConfig as "Auto-Configuration Evaluation"
 participant BeanScan as "Bean Definition Scanning"
 participant Instantiation as "Bean Instantiation"
 
 App->>AutoConfig: Start Phase 1
 Note right of AutoConfig: Cost driver: breadth of classpath
 AutoConfig->>App: Complete Phase 1
 
 App->>BeanScan: Start Phase 2
 Note right of BeanScan: Cost driver: base-package width
 BeanScan->>App: Complete Phase 2
 
 App->>Instantiation: Start Phase 3
 Note right of Instantiation: Cost driver: I/O in init methods
 Instantiation->>App: Complete Phase 3
 
 App->>App: ApplicationContext Ready

Phase 1: Auto-Configuration, Spring's Helpful Guessing Game#

When you add spring-boot-starter-web to your project, you get a working servlet container, Jackson, a DispatcherServlet, error handling, and HTTP message converters without writing a single configuration class. That convenience has a cost: Spring has no idea which of those things you actually need, so it evaluates all of them.

Auto-configuration works through a candidate list. At startup, the framework reads every class registered under the EnableAutoConfiguration key in META-INF/spring.factories (or META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports in newer versions). Each of those classes carries @Conditional annotations that describe when it should apply. Spring instantiates each candidate, inspects your classpath and existing beans, and decides whether to register the configuration or skip it. The skipped ones are not free, evaluating the condition still takes time.2

Add a few Spring Cloud dependencies and that list grows fast. A single microservice pulling in Cloud Config, Sleuth, and a service registry can face enough auto-configuration candidates that Spring spends roughly 20 seconds just working through the list, before your application code touches a single bean.5 That is not a network call or a database round-trip in your code. That is the framework making educated guesses about what you might need.

The blunt fix some teams reach for is replacing @SpringBootApplication's auto-configuration sweep with an explicit @Import list:

Java
@Configuration
@Import({
DispatcherServletAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
JacksonAutoConfiguration.class,
WebMvcAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class
})
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}

This tells Spring exactly which configuration classes to read instead of scanning the whole classpath for candidates. Teams using this approach have cut startup times from roughly 20 seconds to roughly 11 seconds, halving the auto-configuration overhead. The trade-off is maintenance: every time you upgrade Spring Boot you need to audit whether newly added auto-configurations belong on your list.

Before you go that far, running the application with --debug gives you an auto-configuration report showing every candidate, whether it matched, and why.2 Scanning that report usually reveals a handful of configurations that matched but serve features you never use: Redis session management when you have no Redis, Kafka listeners when you only produce messages, Flyway when you already manage migrations elsewhere. Each of those can be excluded with a targeted spring.autoconfigure.exclude property entry, which is less fragile than rewriting the entire import list.

The conditional evaluation model is what makes auto-configuration expensive: Spring cannot skip the evaluation without first knowing the answer. Once you can see exactly which configurations are firing, excluding the ones you don't need is straightforward. At that point, the next phase, classpath scanning, starts to look like the bigger problem.

Phase 2: Classpath Scanning, The Reflection Tax#

When Spring scans for components, it does not have a registry to consult. It walks your classpath, opens every .class file under the configured base-package, and uses the Java Reflection API to ask each class: "Do you carry @Component, @Service, @Repository, or any of their derivatives?" That question, multiplied across thousands of files, is where large applications lose minutes rather than milliseconds.

The Reflection API (Java's built-in mechanism for inspecting class structure at runtime, rather than at compile time) is the underlying tool here because Spring cannot know at compile time what annotations your classes carry. Each reflective call is cheap individually. The problem is the multiplier. A module with five thousand classes under com.mycompany means five thousand reflective inspections, many of them touching classes that will never become beans. The work happens regardless.

The practical impact is not subtle. Developers who have tried narrowing @ComponentScan to the smallest possible set of sub-packages still report scan times of one to two minutes in large applications. Narrowing the package prefix helps because it cuts the population of candidate classes, but it does not change the nature of the work. If your base-package still covers a module with three thousand classes, you still pay three thousand reflective lookups.

The most dramatic evidence of how much scanning costs comes from a workaround that skips it entirely: pre-generating an XML file that lists every bean definition by fully-qualified class name, then loading from that file instead of scanning. One large-application report found that this reduced Spring bootstrap time from over a minute to roughly nine to ten seconds. That is not a small percentage improvement. That is a different order of magnitude, and the only thing that changed was eliminating the reflection walk.

The scan path is a cost boundary. Every package you include is a promise to Spring that it should inspect everything inside. Two common mistakes make this worse than it needs to be. The first is leaving the base-package as the top-level company namespace, com.mycompany, which pulls in utility libraries, generated code, and shared modules that contain no Spring beans at all. The second is placing @SpringBootApplication in a package root and relying on its implicit scan, which by default covers everything at that level and below.

A tightly scoped scan is the first lever. The second is component index pre-computation: since Spring 5, the spring-context-indexer dependency generates a META-INF/spring.components file at build time that maps annotations to classes without any runtime reflection. That annotation processing runs at compile time and produces a flat index Spring reads directly on startup, shifting the reflection cost out of your startup path entirely. Narrowing the scan path alone is only a partial fix. After you have scanning under control, the cost that remains is instantiation order, which is where hidden I/O tends to surface.

Phase 3: Bean Instantiation, Where I/O Hides in Plain Sight#

Auto-configuration and classpath scanning are dramatic offenders, but bean instantiation is sneakier. The cost is invisible because it looks exactly like ordinary object construction. Spring creates your beans one by one on a single thread, and if any of them blocks that thread, every bean downstream waits in silence.

The usual hiding place is @PostConstruct. From the outside it looks like a lifecycle hook, a safe place to do "setup." In practice it is synchronous code running on the same thread that will not move to the next bean until yours returns. If that code makes a network call or fires a query, the entire instantiation sequence stalls.

Java
@Component
public class ExchangeRateCache {
private Map<String, Double> rates;
@PostConstruct
public void loadRates() {
// Blocks here, synchronous HTTP call to an external service.
// This 400ms sits on the single init thread; every downstream
// bean waits behind it.
ResponseEntity<Map> response =
new RestTemplate().getForEntity(
"https://api.ecb.europa.eu/rates", Map.class);
this.rates = response.getBody();
}
}

The block at loadRates() is not logged as a startup problem. Spring records the bean name and moves on once the method returns. A 400ms call here, a 200ms database prefetch in another bean, a config-server round-trip in a third, and you have added a full second to startup without a single suspicious log line.

InitializingBean.afterPropertiesSet() has exactly the same behavior. The interface name implies configuration, but nothing stops a developer from issuing a remote call there. Both mechanisms sit on the critical path of the single initialization thread.4

The natural fix people reach for is making initialization asynchronous, and this has been a known tension in the Spring ecosystem for years. The Spring Framework issue tracker has a long-standing request asking exactly for this: a bean whose init method returns a Future so Spring can proceed to the next bean and join the result only when a dependent bean actually needs it. That feature has not shipped as a first-class API, which means the workaround falls on you: @Async on a separate service method, lazy initialization of the cached data on first use, or an ApplicationReadyEvent listener that loads data after the context is fully built rather than during it.

The ApplicationReadyEvent approach is the cleanest for non-critical warm-up data. Instead of blocking Spring's init thread, you move the load to a listener that fires after the context is ready, meaning your app is serving traffic before the cache is populated. That is the right trade-off for a rates cache. It is the wrong trade-off if other beans depend on the loaded data at startup, in which case deferred loading just moves the block rather than removing it.

All three phases share the same shape: work you did not explicitly request is happening on the critical startup path. Seeing them described separately is useful, but diagnosing your specific app requires measuring each phase in isolation, which is where the next section picks up.

Making the Invisible Visible: Measuring Each Phase#

Knowing the three phases exist does not tell you which one is stealing time in your specific app. Before you touch a single line of configuration, you need a measurement. Guessing which auto-configuration to exclude, or which bean is slow to initialize, produces either no improvement or a broken application.

The fastest way to get data is the --debug flag. Run your jar with it and Spring Boot prints an AUTO-CONFIGURATION REPORT directly to the console before the application finishes starting.2 No code changes, no property file edits. The flag is disposable.

Shell
java -jar myapp-1.0.0.jar --debug

If you are running inside an IDE or want the report captured in a persistent log, add one line to application.properties instead:

Properties
logging.level.org.springframework.boot.autoconfigure=DEBUG

Either way, you will see a block that looks like this in the output2:

Java
=========================
AUTO-CONFIGURATION REPORT
=========================
Positive matches:
-----------------
DataSourceAutoConfiguration matched:
- @ConditionalOnClass found required classes 'javax.sql.DataSource'
Negative matches:
-----------------
ActiveMQAutoConfiguration:
Did not match:
- @ConditionalOnClass did not find required class 'javax.jms.ConnectionFactory'

The "Positive matches" section is your target. Every entry there represents an auto-configuration class that evaluated its conditions, decided they were satisfied, and loaded its beans into the context. The question to ask for each one is simple: does your application actually need this?

The "Negative matches" section is mostly noise for this purpose. Those classes evaluated their conditions and bailed out early, which is cheap. What costs time is everything in the positive list, especially configurations that pull in a chain of dependent beans.

Once you have the positive-matches list, cross-reference it against what your application actually does. A REST API with no messaging code that shows KafkaAutoConfiguration in the positive matches has a classpath problem. A batch job that shows WebMvcAutoConfiguration loading a full servlet stack is dragging unnecessary infrastructure into every startup. The report names the culprits precisely, which makes the fix in the next section, excluding them explicitly, a surgical operation rather than a shot in the dark.

For bean instantiation timing specifically, the report does not help directly. There you want Spring Boot's built-in startup actuator, available since 2.4, which tracks the time each ApplicationContext step takes. Adding spring-boot-starter-actuator to your dependencies and enabling the endpoint gives you per-bean timing you can query at /actuator/startup. That output will surface the one database connection pool or the one remote config fetch that inflates your total startup time while everything else is fast.

Measurement first. Every time.

Pulling the Right Lever: Targeted Fixes for Each Phase#

Once you have the /actuator/startup data and know which phase is costing you time, the fix is almost always straightforward. The mistake is reaching for all three fixes at once without knowing which problem you actually have.

If Phase 1 (auto-configuration) is the culprit, start the app with --debug and read the AUTO-CONFIGURATION REPORT. Every class in the "Positive matches" block was loaded because some condition was satisfied, and many of those classes may be loading infrastructure your app never touches. The fix is to replace the implicit autoconfiguration sweep with an explicit @Import list2:

Java
@Configuration
@Import({
DispatcherServletAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
JacksonAutoConfiguration.class,
WebMvcAutoConfiguration.class,
// only the ones you actually need
})
public class MyApplication {... }

This trades convenience for predictability. Spring stops guessing and loads exactly what you declared.2

If Phase 2 (classpath scanning) is the culprit, the fastest lever is narrowing scanBasePackages on @SpringBootApplication to point only at the packages that actually contain Spring-managed components3. Scanning com.mycompany when all your beans live under com.mycompany.api.handlers forces Spring to open and inspect every class file in every subdirectory first. Give it the smallest valid package prefix and the reflection tax drops proportionally. For containerized workloads where the same JVM cold-starts repeatedly, a further option is caching the scan result at build time into a spring.factories-style file so the runtime reads a pre-built list instead of re-walking the classpath on each container start.5

If Phase 3 (bean instantiation) is the culprit, lazy initialization is the lowest-effort change: set spring.main.lazy-initialization=true in application.properties. Beans are not created until they are first requested, so the startup cost is deferred rather than paid upfront. The trade-off is that the first request to any previously cold bean will carry latency instead, which matters more for some apps than others. For beans that must initialize eagerly but can do their work in parallel, @Async on @PostConstruct methods can move slow I/O off the main startup thread, provided you have verified those beans are not dependencies of something that runs synchronously immediately after.

None of these should be applied as a bundle. The explicit @Import approach makes your configuration harder to read and easier to break when you add a new starter. Lazy initialization can obscure wiring errors that previously failed fast at startup and now fail silently at runtime. Profile, locate the dominant cost, then pull one lever and measure again.

The next thing to run is this: hit GET /actuator/startup while the app is still warm, pipe the JSON through jq '[.timeline.events[] | {duration:.duration, beanName:.startupStep.tags[]?.value}] | sort_by(.duration) | reverse |.[0:10]', and read the top ten. That single sorted list will tell you more about your specific startup problem than any general advice about Spring internals.

Diagram as text
flowchart LR
 A["Run with --debug or set autoconfigure DEBUG logging"] --> B["Read AUTO-CONFIGURATION REPORT"]
 B --> C{"Are there many unneeded auto-configs?"}
 C -->|Yes| D["Exclude with @SpringBootApplication(exclude=...) or explicit @Import"]
 C -->|No| E{"Is base-package broad?"}
 E -->|Yes| F["Narrow scanBasePackages"]
 E -->|No| G["Profile bean init times"]
 G --> H{"Is any bean doing I/O in @PostConstruct?"}
 H -->|Yes| I["Move I/O out of init or mark @Lazy"]
 H -->|No| J["Proceed with current configuration"]

Sources

  1. Spring Boot Performance Tuning & Troubleshooting | OpenLogicopenlogic.com
  2. Speed up Spring Boot startup time - Stack Overflowstackoverflow.com
  3. java - Spring startup performance issues - Stack Overflowstackoverflow.com
  4. Asynchronous initialization of beans during startup [SPR-14920] · Issue #19487 · spring-projects/spring-framework · GitHubgithub.com
  5. Improve startup time : save the auto-configuration discovery result · Issue #10426 · spring-projects/spring-boot · GitHubgithub.com

Keep reading

Spring Boot27 June 2026

How to Scale a Spring Boot App to 1 Million Requests Per Minute

Spring Boot is a Java framework for building web services, and its out-of-the-box configuration is tuned for developer convenience, not production throughput. This article...

17 min readRead the article
Spring Boot22 May 2026

How Spring Security works with JWT, OAuth2, and SSO

Spring Security is a framework that intercepts every HTTP request entering your application and enforces authentication and authorization rules before that request ever reaches a...

14 min readRead the article
Spring Boot21 May 2026

Why Your Spring Boot Service Stalls at 80K RPS (And It's Not the Hardware)

This tutorial walks through a sequence of architectural changes that can take a Spring Boot service from a typical ceiling of 50-80K requests per second to over 1M RPS, without...

17 min readRead the article