0
0
Spring Bootframework~8 mins

Running a Spring Boot application in Spring Boot - Performance & Optimization

Choose your learning style9 modes available
Performance: Running a Spring Boot application
MEDIUM IMPACT
This affects the startup time and initial responsiveness of the web application.
Starting a Spring Boot application for web service
Spring Boot
public static void main(String[] args) {
    SpringApplication app = new SpringApplication(Application.class);
    app.setLazyInitialization(true);
    app.run(args);
}
Enables lazy initialization to delay bean creation until needed, reducing startup time.
📈 Performance Gainreduces startup blocking by up to 30-50%
Starting a Spring Boot application for web service
Spring Boot
public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}
Starting with default settings loads all beans and auto-configurations eagerly, causing slower startup.
📉 Performance Costblocks startup for 3-5 seconds depending on app size
Performance Comparison
PatternStartup TimeMemory UsageResponsivenessVerdict
Default eager startup3-5 secondsHighDelayed initial response[X] Bad
Lazy initialization enabled1.5-3 secondsModerateFaster initial response[OK] Good
Rendering Pipeline
When running a Spring Boot app, the JVM loads classes, initializes beans, and starts embedded server before serving requests.
Class Loading
Bean Initialization
Embedded Server Startup
⚠️ BottleneckBean Initialization is most expensive due to eager loading of many components.
Core Web Vital Affected
LCP
This affects the startup time and initial responsiveness of the web application.
Optimization Tips
1Enable lazy initialization to reduce startup blocking.
2Exclude unused auto-configurations to lower memory and CPU load.
3Use JVM profilers to identify slow bean initializations.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main cause of slow startup in a Spring Boot application?
ALarge HTML files served
BEager loading of all beans and auto-configurations
CSlow network connection
DToo many HTTP requests
DevTools: Spring Boot Actuator and JVM Profilers
How to check: Enable Spring Boot Actuator and use JVM profilers like VisualVM to monitor startup phases and bean loading times.
What to look for: Look for long bean initialization times and high CPU usage during startup to identify bottlenecks.