Update reference manual regarding supported web scopes

This commit is contained in:
Sam Brannen 2016-06-07 18:51:24 +02:00
parent e2810904b0
commit 6804aad06f
2 changed files with 22 additions and 18 deletions

View File

@ -2274,7 +2274,7 @@ the __scope__ of the objects created from a particular bean definition. This app
powerful and flexible in that you can __choose__ the scope of the objects you create
through configuration instead of having to bake in the scope of an object at the Java
class level. Beans can be defined to be deployed in one of a number of scopes: out of
the box, the Spring Framework supports five scopes, three of which are available only if
the box, the Spring Framework supports seven scopes, five of which are available only if
you use a web-aware `ApplicationContext`.
The following scopes are supported out of the box. You can also create
@ -2301,14 +2301,18 @@ The following scopes are supported out of the box. You can also create
| Scopes a single bean definition to the lifecycle of an HTTP `Session`. Only valid in
the context of a web-aware Spring `ApplicationContext`.
| <<beans-factory-scopes-global-session,global session>>
| <<beans-factory-scopes-global-session,globalSession>>
| Scopes a single bean definition to the lifecycle of a global HTTP `Session`. Typically
only valid when used in a portlet context. Only valid in the context of a web-aware
only valid when used in a Portlet context. Only valid in the context of a web-aware
Spring `ApplicationContext`.
| <<beans-factory-scopes-application,application>>
| Scopes a single bean definition to the lifecycle of a `ServletContext`. Only valid in
the context of a web-aware Spring `ApplicationContext`.
| <<websocket-stomp-websocket-scope,websocket>>
| Scopes a single bean definition to the lifecycle of a `WebSocket`. Only valid in
the context of a web-aware Spring `ApplicationContext`.
|===
[NOTE]
@ -2418,22 +2422,22 @@ runtime more than once, see <<beans-factory-method-injection>>
[[beans-factory-scopes-other]]
=== Request, session, and global session scopes
=== request, session, globalSession, application, and websocket scopes
The `request`, `session`, and `global session` scopes are __only__ available if you use
a web-aware Spring `ApplicationContext` implementation (such as
`XmlWebApplicationContext`). If you use these scopes with regular Spring IoC containers
such as the `ClassPathXmlApplicationContext`, you get an `IllegalStateException`
complaining about an unknown bean scope.
The `request`, `session`, `globalSession`, `application`, and `websocket` scopes are
__only__ available if you use a web-aware Spring `ApplicationContext` implementation
(such as `XmlWebApplicationContext`). If you use these scopes with regular Spring IoC
containers such as the `ClassPathXmlApplicationContext`, an `IllegalStateException` will
be thrown complaining about an unknown bean scope.
[[beans-factory-scopes-other-web-configuration]]
==== Initial web configuration
To support the scoping of beans at the `request`, `session`, and `global session` levels
(web-scoped beans), some minor initial configuration is required before you define your
beans. (This initial setup is __not__ required for the standard scopes, `singleton` and
`prototype`.)
To support the scoping of beans at the `request`, `session`, `globalSession`,
`application`, and `websocket` levels (web-scoped beans), some minor initial
configuration is required before you define your beans. (This initial setup is __not__
required for the standard scopes, `singleton` and `prototype`.)
How you accomplish this initial setup depends on your particular Servlet environment.
@ -2543,15 +2547,15 @@ Consider the following bean definition:
<bean id="userPreferences" class="com.foo.UserPreferences" scope="globalSession"/>
----
The `global session` scope is similar to the standard HTTP `Session` scope
The `globalSession` scope is similar to the standard HTTP `Session` scope
(<<beans-factory-scopes-session,described above>>), and applies only in the context of
portlet-based web applications. The portlet specification defines the notion of a global
`Session` that is shared among all portlets that make up a single portlet web
application. Beans defined at the `global session` scope are scoped (or bound) to the
application. Beans defined at the `globalSession` scope are scoped (or bound) to the
lifetime of the global portlet `Session`.
If you write a standard Servlet-based web application and you define one or more beans
as having `global session` scope, the standard HTTP `Session` scope is used, and no
as having `globalSession` scope, the standard HTTP `Session` scope is used, and no
error is raised.

View File

@ -2010,7 +2010,7 @@ public class MyController {
}
----
It is also possible to declare a Spring-managed bean in the `"websocket"` scope.
It is also possible to declare a Spring-managed bean in the `websocket` scope.
WebSocket-scoped beans can be injected into controllers and any channel interceptors
registered on the "clientInboundChannel". Those are typically singletons and live
longer than any individual WebSocket session. Therefore you will need to use a
@ -2020,7 +2020,7 @@ scope proxy mode for WebSocket-scoped beans:
[subs="verbatim,quotes"]
----
@Component
@Scope(name = "websocket", proxyMode = ScopedProxyMode.TARGET_CLASS)
@Scope(scopeName = "websocket", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class MyBean {
@PostConstruct