Spring: Lazy initialisation trades startup time for late failures

spring.main.lazy-initialization=true speeds up boot but moves configuration errors to the first request.

Code
// application.yml
spring:
  main:
    lazy-initialization: true

// Keep one bean eager despite the global setting:
@Component
@Lazy(false)
class MustExistAtStartup { }
Output
Startup: 1.2s instead of 3.8s
But a typo'd datasource URL now fails on the first request, in production.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11