1. What does the request scope mean for a Spring bean?
Why: A request scoped bean lives within a single HTTP request. For each new HTTP request, Spring creates a new instance of the bean.
2. Where is the request scope valid?
Why: The request scope needs an HTTP request to exist, so it is valid only in a web-aware ApplicationContext.
3. Which scope annotation makes a bean live for a single HTTP request?
@Component
// Add scope annotation here
public class UserContext { }
Why: Using @Scope("request") (or the constant WebApplicationContext.SCOPE_REQUEST) creates one bean instance per HTTP request.
4. What is the default scope of a Spring bean when no scope is specified?
Why: If you do not specify a scope, Spring uses the singleton scope. Only one instance of the bean is created.
5. Several beans use a request scoped bean during the same HTTP request. How many instances of the request scoped bean are used?
Why: Within one HTTP request, all beans get the same request scoped instance. This is why data set in one place can be read in another place.
6. Two different HTTP requests arrive at the application. Do they share the same request scoped bean instance?
Why: A new instance is created for each HTTP request. Different requests never share the same request scoped bean.
7. What is a common use of a request scoped bean?
Why: Request scoped beans are useful as helper objects that many beans can use during one request. Their data is not kept after the request ends.
8. What is one advantage of using a request scoped bean to share data?
Why: A request scoped bean holds the shared data, so you do not have to pass it through many methods. Adding new data later is also easier because method signatures do not change.
9. How long does a request scoped bean instance live?
Why: A request scoped bean lives within a single HTTP request. When the request is finished, the instance is no longer used.
10. Why is it a problem to inject a request scoped bean into a singleton bean when no scoped proxy is used?
Why: A singleton bean is created only once, but a request scoped bean needs an active HTTP request and a new instance for each request. Without a scoped proxy or a Provider, the singleton cannot get the right instance.
11. How can a singleton bean get a fresh request scoped bean for each request?
Why: A Provider<T> (JSR 330) gives a bean instance each time get() is called. Calling it during a request returns the instance for that request.
12. Which statement about request scoped beans is correct?
Why: Request scoped beans hold data only for the length of one HTTP request. For longer-lived data, other scopes such as singleton or session are a better fit.