Very slow Spring Boot application startup
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Slow Spring Boot startup is usually a symptom, not the root problem. The delay often comes from expensive bean creation, classpath scanning, database initialization, or libraries doing work during application context refresh. The fastest way to improve startup is to measure where time is going before guessing at fixes.
Find the Slow Phase First
Spring Boot can expose startup details so you can see which beans or phases take time. A practical first step is to enable startup buffering:
With Actuator enabled, you can inspect startup steps through the startup endpoint. That is much more useful than looking only at the total startup duration because it shows which part is actually expensive.
Common Causes of Slow Startup
Several issues show up repeatedly in Spring Boot applications:
- Too many scanned packages and beans.
- Heavy work inside
@PostConstructor bean constructors. - Slow database connections, Flyway, Liquibase, or JPA schema generation.
- Large classpaths with many unused starters and autoconfigurations.
- Excessive logging during startup.
The fix depends on which category dominates. If startup is blocked on the database, tuning component scanning will not help much. If bean creation is the issue, adding more hardware may not help either.
Reduce Unnecessary Bean Creation
A common reason startup gets slow is that the application instantiates far more beans than it needs immediately. Narrowing component scanning and excluding unused autoconfiguration can help significantly.
You should exclude autoconfiguration only when you are sure the feature is not needed. The goal is not to blindly disable things, but to stop loading frameworks that are never used.
Avoid Heavy Startup Logic in Application Code
Developers often place expensive work in bean constructors, @PostConstruct, or startup listeners. Examples include loading large datasets, calling external services, warming caches, or running remote checks. That makes the whole app appear slow even if Spring itself is fine.
Move non-essential work out of the critical path when possible. For example, a cache can sometimes warm asynchronously after the service begins accepting traffic.
This is not always appropriate, but it is better than treating application start as a place to do every possible initialization step.
Be Suspicious of Database Initialization
Hibernate schema creation, validation, Flyway migrations, and slow connection setup are frequent startup bottlenecks. If startup is especially slow in development, check whether the application is doing more database work than expected.
Useful checks include:
- Whether
spring.jpa.hibernate.ddl-autois performing schema operations. - Whether Flyway or Liquibase is scanning a large migration set.
- Whether the configured database is remote and slow to connect.
- Whether connection pool settings cause long retries before failure.
The point is not to disable database checks blindly, but to understand whether they are the dominant cost.
Classpath Size Matters
Every starter you add brings potential autoconfiguration, classpath checks, and bean definitions. Over time, projects accumulate dependencies that were useful once and are now dead weight. Slow startup is often a sign that the classpath should be reviewed.
If the service does not use web sockets, messaging, templating, or security modules, those starters should probably not be on the classpath at all.
Common Pitfalls
- Optimizing random settings without first measuring startup phases.
- Doing expensive work in constructors or
@PostConstruct. - Leaving unused starters on the classpath.
- Assuming slow startup is a Spring problem when the real delay is database or network initialization.
- Turning on lazy loading everywhere without understanding the runtime tradeoff.
Summary
- Measure startup phases first so you know where time is going.
- Reduce unnecessary bean creation and unused autoconfiguration.
- Keep heavy application work out of the critical startup path when possible.
- Check database initialization and connection behavior early.
- Review the dependency list because extra starters often cost real startup time.

