What Is @Lazy in Spring Boot? How It Differs from spring.main.lazy-initialization, How to Measure Startup Time, and the Pitfalls of Lazy Initialization
This article explains lazy initialization in Spring Boot, using constructor logs to check exactly when each Bean is initialized. It covers how @Lazy behaves on a class, a @Bean method, a @Configuration class, and an injection point; when to use @Lazy and when to use spring.main.lazy-initialization=true; how to exclude Beans with @Lazy(false) or LazyInitializationExcludeFilter; how to measure startup time; and the pitfalls you can hit in production. It ends with a decision table.