How to Slash Spring Boot Startup Time by 80%: 10 Proven Optimizations
This article shares ten practical techniques—including lazy bean loading, removing unused auto‑configurations, classloader tweaks, thread‑pool tuning, logging reduction, health‑check disabling, SSD upgrades, Maven packaging fixes, and Arthas monitoring—that together can reduce Spring Boot startup from minutes to seconds, dramatically boosting developer productivity.
Last night at 2 am, a colleague complained that a Spring Boot service took three minutes to start, while his fried chicken went cold. The console was flooded with logs and the startup hung on a bean initialization for half a minute.
10 Startup Optimization Practices (with pitfalls)
1. Lazy‑load Beans: Let 80% of Beans “die”
Operation: Add @Lazy to non‑core beans or enable global lazy loading via YAML.
Result: In an e‑commerce project startup dropped from 98 s to 41 s (‑58%).
Lesson: Do not lazy‑load critical beans such as gateways or authentication; otherwise you may cause time‑outs.
2. Remove Useless AutoConfiguration
Operation: spring.autoconfigure.exclude=xxx to manually exclude unnecessary auto‑configs.
Case: Excluding RedisReactiveAutoConfiguration in a payment service that only uses MySQL saved 12 s.
Tip: Use /actuator/conditions endpoint to view auto‑configuration report.
3. ClassLoader Optimizations
Parallel class loading on multi‑core servers – speed up 20‑30%.
Class cache sharing in micro‑service clusters – reduces duplicate loads.
Adjust loading order to avoid deadlocks in heavy dependency conflicts.
Real case: Reordering ClassLoader reduced startup from 4 min to 1 min 50 s.
4. ThreadPool on‑Demand Startup
Trick: Set
ThreadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown=false.
Result: 8 idle threads removed, saved 300 MB memory, startup 9 s faster.
5. Slim Logging
Example configuration:
logging:
level:
org.hibernate: ERROR
com.zaxxer.hikari: WARNEffect: Log volume reduced by 70%, startup accelerated by 15%.
6. Disable Unnecessary Health Checks
Problem: Spring Boot probes DB and Redis health by default, causing delays.
Solution: management.health.defaults.enabled: false and enable only needed checks.
Lesson: A missing RabbitMQ caused a 2‑minute block.
7. Remove Pre‑installed Bloatware
Issue: Test machine shipped with a “security guard” service launching 37 processes, CPU at 97%.
Fix: Use msconfig or chkconfig to disable unnecessary services.
8. SSD vs HDD
Default config: HDD 4 min 20 s, SSD 1 min 50 s.
Optimized config: HDD 1 min 10 s, SSD 22 s.
Takeaway: Investing in SSD can cut minutes off startup.
9. Maven Packaging Pitfall
Cold fact: mvn package includes spring-boot-devtools by default, adding ~15% startup time.
Rescue command: mvn package -Dspring-boot.excludeDevtools=true.
10. Monitor Startup with Arthas
Command:
trace org.springframework.context.support.AbstractApplicationContext refreshto trace bean initialization.
Finding: An XML‑based bean took 47 s; switching to annotation reduced it by 80%.
Conclusion: Optimizing Spring Boot startup is not mystic; it requires questioning default settings, applying lazy loading, trimming auto‑config, and monitoring the process. Cutting startup from minutes to seconds dramatically improves developer productivity.
After applying the plan, a colleague reported a 22‑second startup, finally allowing hot fried chicken.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
