liveBook · Manning

Chapter 9: Using the Spring web scopes

What you will learn in chapter 9 of Spring Start Here, Second Edition

Introduces Spring’s three web bean scopes by comparing how long their instances are available.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces Spring’s three web bean scopes by comparing how long their instances are available.

Key terms: web scopes, request scope, session scope, application scope

9.1 Using the request scope in a Spring web app

Explains how request-scoped beans give each HTTP request its own bean instance, using a login example to show when and how to use the scope.

Key terms: request-scoped bean, HTTP request, instance, LoginController, LoginProcessor, credentials, singleton, @RequestScoped, @Component, message

9.2 Using the session scope in a Spring web app

This section explains how session-scoped beans retain data across one client’s requests and uses a stored username to implement login, protected-page access, and logout.

Key terms: session-scoped bean, HTTP session, request-scoped bean, @SessionScope, LoggedUserManagementService, LoginProcessor, username, MainController, /main, redirect:

9.3 Using the application scope in a Spring web app

This section explains how application-scoped beans share state across clients, illustrates that behavior with a login counter, and cautions against using the scope in production.

Key terms: application scope, application-scoped bean, singleton, concurrency problems, immutable attributes, singleton bean, persistence layer, database, LoginCountService, LoginProcessor

9.4 Questions

This section provides review questions about request, session, and application scopes and when to use a database instead.

9.5 Summary

Summarizes how request, session, and application bean scopes differ in lifetime and sharing, and the design risks of keeping data in longer-lived scopes.

Concepts explained in this chapter

← Chapter 8: Implementing web apps with Spring Boot and Spring MVC Chapter 10: Implementing REST endpoints →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.