Spring Boot app takes 40 seconds to start — how to find what's slow?

asked a month ago116 viewsen

6

Our Spring Boot service's startup has crept up to 40s, which hurts deploys and autoscaling. How do I profile startup?

AI diagnosis

AI-generated. Not an answer — the community below confirms or corrects it. Always verify before relying on it.

asked a month ago

1 Answer

7
✓
✓ Accepted answer

1. Startup actuator endpoint: record bean initialization times:

SpringApplication app = new SpringApplication(App.class);
app.setApplicationStartup(new BufferingApplicationStartup(2048));
app.run(args);

Then GET /actuator/startup lists the slowest steps.

2. Common culprits: Hibernate ddl-auto=update or validation on a big schema, classpath scanning over huge packages, eager connections to slow external services, and Flyway migrations.

3. Quick wins: - spring.main.lazy-initialization=true (test it carefully). - spring.jpa.open-in-view=false, and set ddl-auto to none in production. - Run on Java 21+ with Class Data Sharing (AppCDS). For the biggest gain, consider GraalVM native image or CRaC (checkpoint/restore).

Sign in to tell others whether this worked.

answered a month ago

Sign in and verify your email to post an answer.