@@ -2274,7 +2274,7 @@ the __scope__ of the objects created from a particular bean definition. This app
2274
2274
powerful and flexible in that you can __choose__ the scope of the objects you create
2275
2275
through configuration instead of having to bake in the scope of an object at the Java
2276
2276
class level. Beans can be defined to be deployed in one of a number of scopes: out of
2277
- the box, the Spring Framework supports five scopes, three of which are available only if
2277
+ the box, the Spring Framework supports seven scopes, five of which are available only if
2278
2278
you use a web-aware `ApplicationContext`.
2279
2279
2280
2280
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
2301
2301
| Scopes a single bean definition to the lifecycle of an HTTP `Session`. Only valid in
2302
2302
the context of a web-aware Spring `ApplicationContext`.
2303
2303
2304
- | <<beans-factory-scopes-global-session,global session >>
2304
+ | <<beans-factory-scopes-global-session,globalSession >>
2305
2305
| Scopes a single bean definition to the lifecycle of a global HTTP `Session`. Typically
2306
- only valid when used in a portlet context. Only valid in the context of a web-aware
2306
+ only valid when used in a Portlet context. Only valid in the context of a web-aware
2307
2307
Spring `ApplicationContext`.
2308
2308
2309
2309
| <<beans-factory-scopes-application,application>>
2310
2310
| Scopes a single bean definition to the lifecycle of a `ServletContext`. Only valid in
2311
2311
the context of a web-aware Spring `ApplicationContext`.
2312
+
2313
+ | <<websocket-stomp-websocket-scope,websocket>>
2314
+ | Scopes a single bean definition to the lifecycle of a `WebSocket`. Only valid in
2315
+ the context of a web-aware Spring `ApplicationContext`.
2312
2316
|===
2313
2317
2314
2318
[NOTE]
@@ -2418,22 +2422,22 @@ runtime more than once, see <<beans-factory-method-injection>>
2418
2422
2419
2423
2420
2424
[[beans-factory-scopes-other]]
2421
- === Request, session, and global session scopes
2425
+ === Request, session, global session, application, and WebSocket scopes
2422
2426
2423
- The `request`, `session`, and `global session` scopes are __only__ available if you use
2424
- a web-aware Spring `ApplicationContext` implementation (such as
2425
- `XmlWebApplicationContext`). If you use these scopes with regular Spring IoC containers
2426
- such as the `ClassPathXmlApplicationContext`, you get an `IllegalStateException`
2427
- complaining about an unknown bean scope.
2427
+ The `request`, `session`, `globalSession`, `application`, and `websocket` scopes are
2428
+ __only__ available if you use a web-aware Spring `ApplicationContext` implementation
2429
+ (such as `XmlWebApplicationContext`). If you use these scopes with regular Spring IoC
2430
+ containers such as the `ClassPathXmlApplicationContext`, an `IllegalStateException` will
2431
+ be thrown complaining about an unknown bean scope.
2428
2432
2429
2433
2430
2434
[[beans-factory-scopes-other-web-configuration]]
2431
2435
==== Initial web configuration
2432
2436
2433
- To support the scoping of beans at the `request`, `session`, and `global session` levels
2434
- (web-scoped beans), some minor initial configuration is required before you define your
2435
- beans. (This initial setup is __not__ required for the standard scopes, `singleton` and
2436
- `prototype`.)
2437
+ To support the scoping of beans at the `request`, `session`, `globalSession`,
2438
+ `application`, and `websocket` levels (web-scoped beans), some minor initial
2439
+ configuration is required before you define your beans. (This initial setup is __not__
2440
+ required for the standard scopes, `singleton` and `prototype`.)
2437
2441
2438
2442
How you accomplish this initial setup depends on your particular Servlet environment.
2439
2443
@@ -2493,7 +2497,7 @@ down the call chain.
2493
2497
[[beans-factory-scopes-request]]
2494
2498
==== Request scope
2495
2499
2496
- Consider the following bean definition:
2500
+ Consider the following XML configuration for a bean definition:
2497
2501
2498
2502
[source,xml,indent=0]
2499
2503
[subs="verbatim,quotes"]
@@ -2513,7 +2517,7 @@ bean that is scoped to the request is discarded.
2513
2517
[[beans-factory-scopes-session]]
2514
2518
==== Session scope
2515
2519
2516
- Consider the following bean definition:
2520
+ Consider the following XML configuration for a bean definition:
2517
2521
2518
2522
[source,xml,indent=0]
2519
2523
[subs="verbatim,quotes"]
@@ -2543,22 +2547,22 @@ Consider the following bean definition:
2543
2547
<bean id="userPreferences" class="com.foo.UserPreferences" scope="globalSession"/>
2544
2548
----
2545
2549
2546
- The `global session ` scope is similar to the standard HTTP `Session` scope
2550
+ The `globalSession ` scope is similar to the standard HTTP `Session` scope
2547
2551
(<<beans-factory-scopes-session,described above>>), and applies only in the context of
2548
2552
portlet-based web applications. The portlet specification defines the notion of a global
2549
2553
`Session` that is shared among all portlets that make up a single portlet web
2550
- application. Beans defined at the `global session ` scope are scoped (or bound) to the
2554
+ application. Beans defined at the `globalSession ` scope are scoped (or bound) to the
2551
2555
lifetime of the global portlet `Session`.
2552
2556
2553
2557
If you write a standard Servlet-based web application and you define one or more beans
2554
- as having `global session ` scope, the standard HTTP `Session` scope is used, and no
2558
+ as having `globalSession ` scope, the standard HTTP `Session` scope is used, and no
2555
2559
error is raised.
2556
2560
2557
2561
2558
2562
[[beans-factory-scopes-application]]
2559
2563
==== Application scope
2560
2564
2561
- Consider the following bean definition:
2565
+ Consider the following XML configuration for a bean definition:
2562
2566
2563
2567
[source,xml,indent=0]
2564
2568
[subs="verbatim,quotes"]
@@ -2637,12 +2641,12 @@ understand the "why" as well as the "how" behind it.
2637
2641
----
2638
2642
2639
2643
To create such a proxy, you insert a child `<aop:scoped-proxy/>` element into a scoped
2640
- bean definition. See <<beans-factory-scopes-other-injection-proxies>> and
2641
- <<xsd-configuration>>.) Why do definitions of beans scoped at the `request`, `session`,
2642
- `globalSession` and custom-scope levels require the `<aop:scoped-proxy/>` element ?
2644
+ bean definition (see <<beans-factory-scopes-other-injection-proxies>> and
2645
+ <<xsd-configuration>>). Why do definitions of beans scoped at the `request`, `session`,
2646
+ `globalSession` and custom-scope levels require the `<aop:scoped-proxy/>` element?
2643
2647
Let's examine the following singleton bean definition and contrast it with what you need
2644
- to define for the aforementioned scopes. (The following `userPreferences` bean
2645
- definition as it stands is __incomplete.)__
2648
+ to define for the aforementioned scopes (note that the following `userPreferences` bean
2649
+ definition as it stands is __incomplete__).
2646
2650
2647
2651
[source,xml,indent=0]
2648
2652
[subs="verbatim,quotes"]
@@ -3126,7 +3130,7 @@ You configure destroy method callbacks similarly (in XML, that is) by using the
3126
3130
3127
3131
Where existing bean classes already have callback methods that are named at variance
3128
3132
with the convention, you can override the default by specifying (in XML, that is) the
3129
- method name using the `init-method` and `destroy-method` attributes of the <bean/>
3133
+ method name using the `init-method` and `destroy-method` attributes of the ` <bean/>`
3130
3134
itself.
3131
3135
3132
3136
The Spring container guarantees that a configured initialization callback is called
@@ -3395,7 +3399,7 @@ a reference to the name defined in its associated object definition.
3395
3399
----
3396
3400
public interface BeanNameAware {
3397
3401
3398
- void setBeanName(string name) throws BeansException;
3402
+ void setBeanName(String name) throws BeansException;
3399
3403
3400
3404
}
3401
3405
----
@@ -4227,18 +4231,18 @@ arguments:
4227
4231
}
4228
4232
----
4229
4233
4230
- You can apply `@Autowired` to constructors and fields :
4234
+ You can apply `@Autowired` to fields as well and even mix it with constructors :
4231
4235
4232
4236
[source,java,indent=0]
4233
4237
[subs="verbatim,quotes"]
4234
4238
----
4235
4239
public class MovieRecommender {
4236
4240
4241
+ private final CustomerPreferenceDao customerPreferenceDao;
4242
+
4237
4243
@Autowired
4238
4244
private MovieCatalog movieCatalog;
4239
4245
4240
- private CustomerPreferenceDao customerPreferenceDao;
4241
-
4242
4246
@Autowired
4243
4247
public MovieRecommender(CustomerPreferenceDao customerPreferenceDao) {
4244
4248
this.customerPreferenceDao = customerPreferenceDao;
@@ -4373,7 +4377,7 @@ automatically resolved, with no special setup necessary.
4373
4377
4374
4378
[NOTE]
4375
4379
====
4376
- `@Autowired`, `@Inject`, `@Resource`, and `@Value` annotations are handled by a Spring
4380
+ `@Autowired`, `@Inject`, `@Resource`, and `@Value` annotations are handled by Spring
4377
4381
`BeanPostProcessor` implementations which in turn means that you __cannot__ apply these
4378
4382
annotations within your own `BeanPostProcessor` or `BeanFactoryPostProcessor` types (if
4379
4383
any). These types must be 'wired up' explicitly via XML or using a Spring `@Bean` method.
@@ -4573,8 +4577,8 @@ to the specific collection or map bean by unique name.
4573
4577
4574
4578
`@Autowired` applies to fields, constructors, and multi-argument methods, allowing for
4575
4579
narrowing through qualifier annotations at the parameter level. By contrast, `@Resource`
4576
- is supported only for fields and bean property setter methods with a single argument. As
4577
- a consequence, stick with qualifiers if your injection target is a constructor or a
4580
+ is supported only for fields and bean property setter methods with a single argument.
4581
+ As a consequence, stick with qualifiers if your injection target is a constructor or a
4578
4582
multi-argument method.
4579
4583
====
4580
4584
@@ -5324,9 +5328,9 @@ and the equivalent using XML
5324
5328
[NOTE]
5325
5329
====
5326
5330
You can also disable the default filters by setting `useDefaultFilters=false` on the annotation or
5327
- providing `use-default-filters="false"` as an attribute of the <component-scan/> element. This
5331
+ providing `use-default-filters="false"` as an attribute of the ` <component-scan/>` element. This
5328
5332
will in effect disable automatic detection of classes annotated with `@Component`, `@Repository`,
5329
- `@Service`, or `@Controller `.
5333
+ `@Service`, `@Controller`, or `@Configuration `.
5330
5334
====
5331
5335
5332
5336
@@ -5474,14 +5478,14 @@ analogous to how the container selects between multiple `@Autowired` constructor
5474
5478
5475
5479
When a component is autodetected as part of the scanning process, its bean name is
5476
5480
generated by the `BeanNameGenerator` strategy known to that scanner. By default, any
5477
- Spring stereotype annotation ( `@Component`, `@Repository`, `@Service`, and
5478
- `@Controller`) that contains a `name` value will thereby provide that name to the
5481
+ Spring stereotype annotation (`@Component`, `@Repository`, `@Service`, and
5482
+ `@Controller`) that contains a _name_ ` value` will thereby provide that name to the
5479
5483
corresponding bean definition.
5480
5484
5481
- If such an annotation contains no `name` value or for any other detected component (such
5485
+ If such an annotation contains no _name_ ` value` or for any other detected component (such
5482
5486
as those discovered by custom filters), the default bean name generator returns the
5483
5487
uncapitalized non-qualified class name. For example, if the following two components
5484
- were detected, the names would be myMovieLister and movieFinderImpl:
5488
+ were detected, the names would be ` myMovieLister` and ` movieFinderImpl` :
5485
5489
5486
5490
[source,java,indent=0]
5487
5491
[subs="verbatim,quotes"]
@@ -5539,8 +5543,8 @@ auto-generated names are adequate whenever the container is responsible for wiri
5539
5543
=== Providing a scope for autodetected components
5540
5544
5541
5545
As with Spring-managed components in general, the default and most common scope for
5542
- autodetected components is singleton. However, sometimes you need other scopes, which
5543
- Spring 2.5 provides with a new `@Scope` annotation. Simply provide the name of the scope
5546
+ autodetected components is ` singleton` . However, sometimes you need a different scope
5547
+ which can be specified via the `@Scope` annotation. Simply provide the name of the scope
5544
5548
within the annotation:
5545
5549
5546
5550
[source,java,indent=0]
@@ -5830,7 +5834,7 @@ Please use Spring's stereotype model for building custom component annotations.
5830
5834
5831
5835
5832
5836
[[beans-standard-annotations-limitations]]
5833
- === Limitations of the standard approach
5837
+ === Limitations of JSR-330 standard annotations
5834
5838
5835
5839
When working with standard annotations, it is important to know that some significant
5836
5840
features are not available as shown in the table below:
0 commit comments