liveBook · Manning

@RequestScoped annotation

As explained in Spring Start Here, Second Edition

The @RequestScoped annotation marks a Spring bean as having request scope.

In a Spring web app, @RequestScoped gives a bean a separate instance for each HTTP request. Request-specific data, such as login credentials, stays independent and is not kept beyond the request. section 9.1

Login credentials

A LoginProcessor stores the username and password received by the controller, then validates them. Marking it request-scoped gives each login request its own processor instance; register the bean with @Component or @Bean as well. section 9.1

How Spring Start Here, Second Edition covers it

How deep it goes
Explains per-request bean instances through a worked LoginProcessor example and controller wiring.
Examples
Uses a LoginProcessor to hold credentials and validate a login request.
What you can do after
Apply it in Spring to give each HTTP request its own bean instance for request-local data.
How it connects
Connects request-scoped beans with Spring components, controllers, HTTP requests, and session-scoped beans.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.