Learning Spring Boot from Zero to Cloud: Part 28 – Scope Prototype, ApplicationContext, ObjectFactory josedacruz, May 9, 2025May 9, 2025 In this video, we take a comprehensive look at prototype scope in Spring Boot, when and how to use it, and the best practices around injecting prototype-scoped beans into singleton-scoped components. This is part of a growing series, so make sure to check the playlist for more hands-on Spring Boot topics! 🔥 Whether you’re a backend developer optimizing multi-threaded jobs, or trying to manage bean lifecycle more effectively, this session will give you both the theory and practical code examples to master @Scope("prototype"). 👇 What you’ll learn in this video:🔍 The difference between singleton and prototype scopes🎯 Real-world use cases where prototype makes sense⚙️ How ObjectFactory<T> and ApplicationContext differ and when to use each🛠️ Step-by-step: injecting prototype beans correctly📊 Detailed comparisons and clean code samples🚨 What not to do: common pitfalls and performance concerns ⏱️ Timestamps00:00 – Introduction, Scopes in Spring01:53 – Prototype Scope: What is it?03:37 – Why Use Prototype Scope?04:20 – Singleton vs Prototype Scope (visualization)04:45 – Drawbacks of Prototype Scope06:34 – Real-World Example: Report Generation08:13 – Creating a Prototype Bean09:45 – Problem: Prototype in Singleton11:32 – Using ObjectFactory for Lazy Injection12:52 – ApplicationContext – Full Spring Container16:55 – @Configuration and @Bean – Prototype Scope17:30 – @Component and @Scope – Prototype Scope19:16 – Best Practices21:22 – Summary22:22 – Code Walkthrough 📂 GitHub Repository with All Code Examples:👉 https://github.com/josedacruz/youtube-springboot 💬 Have a question or need clarification? Drop it in the comments!👍 Like, 🔁 share, and 🔔 subscribe so you don’t miss the next episode. Related spring-boot