0PricingLogin
Spring Boot 4 Microservices & REST APIs · Lesson

Bean Scopes

Singleton, prototype, request, and session scopes.

What a Scope Controls

A bean’s scope determines how many instances the container creates and how long each lives. The default and most common scope is singleton.

Choosing the right scope matters for state, memory, and thread safety.

Singleton Scope

With singleton scope, the container creates exactly one instance per ApplicationContext and returns it for every injection point. This is ideal for stateless services.

@Service // singleton by default
public class PricingService {
    public BigDecimal price(Order o) { /* stateless */ }
}

All lessons in this course

  1. The Spring IoC Container
  2. Constructor vs Field Injection
  3. Bean Scopes
  4. Lifecycle Callbacks
← Back to Spring Boot 4 Microservices & REST APIs