Spring Boot Bean Lifecycle Trivia

Four questions on Spring's bean lifecycle: scopes, init / destroy callbacks, circular dependencies, and conditional beans. Aimed at Java backend candidates who keep getting tripped up by the container.

Question Bundle
Java
4 questions
framework
java-annotations
interview-prep

By CodeSnatch

April 20, 2026

·

Updated May 20, 2026

1,159 views

8

4.5 (12)

A service is annotated @Service and injected into a controller. The team wants a new instance per HTTP request instead of the default singleton. Show two ways to do it and explain the trap when a singleton injects a request-scoped bean.

Examples

Example 1:

Input: CartService scoped request with proxyMode = TARGET_CLASS, injected into singleton CartController; two GET /checkout requests
Output: two distinct CartService instances
Explanation: The proxy resolves the actual bean from the current request scope on each access.

Example 2:

Input: Inject request-scoped CartService directly without proxyMode into a singleton
Output: BeanCreationException at startup
Explanation: Spring tries to resolve the dependency at context startup when no request is active.
// Conceptual: in Spring, this @Service is a singleton by default.
// @Service
class CartService {
    public String checkout() { return "ok"; }
}

public class Main {
    public static void main(String[] args) {
        CartService svc = new CartService();
        System.out.println(svc.checkout());
    }
}