Overview - @Scope for bean scope
What is it?
@Scope is an annotation in Spring Boot that controls the lifecycle and visibility of a bean. It tells Spring how long a bean should live and how many instances should be created. Common scopes include singleton (one instance for the whole app) and prototype (a new instance every time). This helps manage resources and behavior in your application.
Why it matters
Without @Scope, all beans would behave the same way, usually as singletons. This can cause problems when you need fresh data or separate instances for different users or requests. @Scope solves this by letting you control bean creation and lifespan, making your app more efficient and easier to maintain. Imagine if every tool in a workshop was shared by everyone all the time — it would cause delays and confusion.
Where it fits
Before learning @Scope, you should understand what beans are and how Spring manages them with dependency injection. After mastering @Scope, you can explore advanced Spring features like custom scopes, request/session scopes in web apps, and lifecycle callbacks.