From 47d77252d3d5a4b3500200864da214d7e5869d09 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 7 Jun 2016 18:53:55 +0200 Subject: [PATCH] Document web scope annotations in the reference manual Issue: SPR-13994 --- src/asciidoc/core-beans.adoc | 47 +++++++++++++++++++++++++++++++++--- src/asciidoc/whats-new.adoc | 8 ++++-- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/asciidoc/core-beans.adoc b/src/asciidoc/core-beans.adoc index f2f5f29fb5..5f7f41d8c4 100644 --- a/src/asciidoc/core-beans.adoc +++ b/src/asciidoc/core-beans.adoc @@ -2422,7 +2422,7 @@ runtime more than once, see <> [[beans-factory-scopes-other]] -=== request, session, globalSession, application, and websocket scopes +=== Request, session, global session, application, and WebSocket scopes The `request`, `session`, `globalSession`, `application`, and `websocket` scopes are __only__ available if you use a web-aware Spring `ApplicationContext` implementation @@ -2497,7 +2497,7 @@ down the call chain. [[beans-factory-scopes-request]] ==== Request scope -Consider the following bean definition: +Consider the following XML configuration for a bean definition: [source,xml,indent=0] [subs="verbatim,quotes"] @@ -2513,11 +2513,24 @@ created from the same `loginAction` bean definition will not see these changes i they are particular to an individual request. When the request completes processing, the bean that is scoped to the request is discarded. +When using Java Config, the `@RequestScope` annotation can be used to assign a component +to the `request` scope. + +[source,java,indent=0] +[subs="verbatim,quotes"] +---- + @RequestScope + @Component + public class LoginAction { + // ... + } +---- + [[beans-factory-scopes-session]] ==== Session scope -Consider the following bean definition: +Consider the following XML configuration for a bean definition: [source,xml,indent=0] [subs="verbatim,quotes"] @@ -2535,6 +2548,19 @@ changes in state, because they are particular to an individual HTTP `Session`. W HTTP `Session` is eventually discarded, the bean that is scoped to that particular HTTP `Session` is also discarded. +When using Java Config, the `@SessionScope` annotation can be used to assign a component +to the `session` scope. + +[source,java,indent=0] +[subs="verbatim,quotes"] +---- + @SessionScope + @Component + public class UserPreferences { + // ... + } +---- + [[beans-factory-scopes-global-session]] ==== Global session scope @@ -2562,7 +2588,7 @@ error is raised. [[beans-factory-scopes-application]] ==== Application scope -Consider the following bean definition: +Consider the following XML configuration for a bean definition: [source,xml,indent=0] [subs="verbatim,quotes"] @@ -2578,6 +2604,19 @@ differs in two important ways: It is a singleton per `ServletContext`, not per S 'ApplicationContext' (for which there may be several in any given web application), and it is actually exposed and therefore visible as a `ServletContext` attribute. +When using Java Config, the `@ApplicationScope` annotation can be used to assign a +component to the `application` scope. + +[source,java,indent=0] +[subs="verbatim,quotes"] +---- + @ApplicationScope + @Component + public class AppPreferences { + // ... + } +---- + [[beans-factory-scopes-other-injection]] ==== Scoped beans as dependencies diff --git a/src/asciidoc/whats-new.adoc b/src/asciidoc/whats-new.adoc index b24a49eba0..63ac05749a 100644 --- a/src/asciidoc/whats-new.adoc +++ b/src/asciidoc/whats-new.adoc @@ -674,8 +674,12 @@ Spring 4.3 also improves the caching abstraction as follows: * Built-in support for <>. * New `@GetMapping`, `@PostMapping`, `@PutMapping`, `@DeleteMapping`, and `@PatchMapping` _composed annotations_ for `@RequestMapping`. -** See <> for details. -* New `@RequestScope`, `@SessionScope`, and `@ApplicationScope` _composed annotations_ for web scopes. +** See <> for details. +* New `@RequestScope`, `@SessionScope`, and `@ApplicationScope` _composed annotations_ + for web scopes. +** See <>, + <>, and + <> for details. * New `@RestControllerAdvice` annotation with combined `@ControllerAdvice` with `@ResponseBody` semantics. * `@ResponseStatus` is now supported at the class level and inherited by all methods. * New `@SessionAttribute` annotation for access to session attributes (see <>). -- GitLab