1. Which bean scope creates one bean instance for each HTTP session?
Why: A session scoped bean is created once for each HTTP session. Every user session gets its own instance.
2. Which web scopes can be used for objects injected into a Spring MVC controller?
Why: Spring MVC supports the request, session and application scopes for objects injected into controllers.
3. How long does a session scoped bean stay alive?
Why: A session scoped bean is kept for the whole life of the HTTP session. It is removed when the session ends.
4. Where does Spring keep a session scoped bean?
Why: Spring stores the session scoped bean in the HttpSession. It stays there until the session ends.
5. Which annotation makes a bean definition session scoped?
Why: Use @Scope with the session scope name, for example WebApplicationContext.SCOPE_SESSION, to make a bean session scoped.
6. When does Spring call the factory method of a session scoped bean?
Why: Spring calls the factory method when a new HTTP session needs the bean. The returned object is then kept in that session.
7. Two different users visit a web application at the same time. How many instances of a session scoped bean are used?
Why: Each HTTP session has its own bean instance. Data of one user is not visible to another user.
8. One user sends many requests in the same HTTP session. Which instance of a session scoped bean is used?
Why: The bean lives as long as the session. All requests in the same session use the same instance.
9. What is the problem when a session scoped bean is injected directly into a singleton controller?
Why: A singleton is created and injected only once. A shorter-lived bean, like a session bean, needs a way to be looked up again for each session.
10. Which approach helps a singleton controller to get the correct session scoped bean?
Why: A Provider<T> (JSR 330) delays the lookup. Each call to get() returns the bean of the current session.
11. A controller calls get() on a Provider<T> of a session scoped bean several times during the same session. What does it return?
Why: Within one session, get() returns the same session scoped instance. Another session gets its own instance.
12. Which of these is another way to work with session data in a Spring MVC controller?
Why: Besides session scoped beans, you can use @SessionAttributes or take HttpSession as a controller method argument.