Skip to content

Commit 47d7725

Browse files
committed
Document web scope annotations in the reference manual
Issue: SPR-13994
1 parent 6804aad commit 47d7725

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

src/asciidoc/core-beans.adoc

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,7 +2422,7 @@ runtime more than once, see <<beans-factory-method-injection>>
24222422

24232423

24242424
[[beans-factory-scopes-other]]
2425-
=== request, session, globalSession, application, and websocket scopes
2425+
=== Request, session, global session, application, and WebSocket scopes
24262426

24272427
The `request`, `session`, `globalSession`, `application`, and `websocket` scopes are
24282428
__only__ available if you use a web-aware Spring `ApplicationContext` implementation
@@ -2497,7 +2497,7 @@ down the call chain.
24972497
[[beans-factory-scopes-request]]
24982498
==== Request scope
24992499

2500-
Consider the following bean definition:
2500+
Consider the following XML configuration for a bean definition:
25012501

25022502
[source,xml,indent=0]
25032503
[subs="verbatim,quotes"]
@@ -2513,11 +2513,24 @@ created from the same `loginAction` bean definition will not see these changes i
25132513
they are particular to an individual request. When the request completes processing, the
25142514
bean that is scoped to the request is discarded.
25152515

2516+
When using Java Config, the `@RequestScope` annotation can be used to assign a component
2517+
to the `request` scope.
2518+
2519+
[source,java,indent=0]
2520+
[subs="verbatim,quotes"]
2521+
----
2522+
@RequestScope
2523+
@Component
2524+
public class LoginAction {
2525+
// ...
2526+
}
2527+
----
2528+
25162529

25172530
[[beans-factory-scopes-session]]
25182531
==== Session scope
25192532

2520-
Consider the following bean definition:
2533+
Consider the following XML configuration for a bean definition:
25212534

25222535
[source,xml,indent=0]
25232536
[subs="verbatim,quotes"]
@@ -2535,6 +2548,19 @@ changes in state, because they are particular to an individual HTTP `Session`. W
25352548
HTTP `Session` is eventually discarded, the bean that is scoped to that particular HTTP
25362549
`Session` is also discarded.
25372550

2551+
When using Java Config, the `@SessionScope` annotation can be used to assign a component
2552+
to the `session` scope.
2553+
2554+
[source,java,indent=0]
2555+
[subs="verbatim,quotes"]
2556+
----
2557+
@SessionScope
2558+
@Component
2559+
public class UserPreferences {
2560+
// ...
2561+
}
2562+
----
2563+
25382564

25392565
[[beans-factory-scopes-global-session]]
25402566
==== Global session scope
@@ -2562,7 +2588,7 @@ error is raised.
25622588
[[beans-factory-scopes-application]]
25632589
==== Application scope
25642590

2565-
Consider the following bean definition:
2591+
Consider the following XML configuration for a bean definition:
25662592

25672593
[source,xml,indent=0]
25682594
[subs="verbatim,quotes"]
@@ -2578,6 +2604,19 @@ differs in two important ways: It is a singleton per `ServletContext`, not per S
25782604
'ApplicationContext' (for which there may be several in any given web application),
25792605
and it is actually exposed and therefore visible as a `ServletContext` attribute.
25802606

2607+
When using Java Config, the `@ApplicationScope` annotation can be used to assign a
2608+
component to the `application` scope.
2609+
2610+
[source,java,indent=0]
2611+
[subs="verbatim,quotes"]
2612+
----
2613+
@ApplicationScope
2614+
@Component
2615+
public class AppPreferences {
2616+
// ...
2617+
}
2618+
----
2619+
25812620

25822621
[[beans-factory-scopes-other-injection]]
25832622
==== Scoped beans as dependencies

src/asciidoc/whats-new.adoc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,12 @@ Spring 4.3 also improves the caching abstraction as follows:
674674
* Built-in support for <<mvc-ann-requestmapping-head-options,HTTP HEAD and HTTP OPTIONS>>.
675675
* New `@GetMapping`, `@PostMapping`, `@PutMapping`, `@DeleteMapping`, and `@PatchMapping`
676676
_composed annotations_ for `@RequestMapping`.
677-
** See <<mvc-ann-requestmapping-composed>> for details.
678-
* New `@RequestScope`, `@SessionScope`, and `@ApplicationScope` _composed annotations_ for web scopes.
677+
** See <<mvc-ann-requestmapping-composed,Composed @RequestMapping Variants>> for details.
678+
* New `@RequestScope`, `@SessionScope`, and `@ApplicationScope` _composed annotations_
679+
for web scopes.
680+
** See <<beans-factory-scopes-request,Request scope>>,
681+
<<beans-factory-scopes-session,Session scope>>, and
682+
<<beans-factory-scopes-application,Application scope>> for details.
679683
* New `@RestControllerAdvice` annotation with combined `@ControllerAdvice` with `@ResponseBody` semantics.
680684
* `@ResponseStatus` is now supported at the class level and inherited by all methods.
681685
* New `@SessionAttribute` annotation for access to session attributes (see <<mvc-ann-sessionattrib-global, example>>).

0 commit comments

Comments
 (0)