Skip to content

Commit c2bd229

Browse files
committed
Clarify role of 'aware' callback interfaces
1 parent ac0e5d8 commit c2bd229

File tree

2 files changed

+41
-43
lines changed

2 files changed

+41
-43
lines changed

src/docs/asciidoc/core/core-beans.adoc

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3746,16 +3746,16 @@ Thus, beans can programmatically manipulate the `ApplicationContext` that create
37463746
through the `ApplicationContext` interface or by casting the reference to a known
37473747
subclass of this interface (such as `ConfigurableApplicationContext`, which exposes
37483748
additional functionality). One use would be the programmatic retrieval of other beans.
3749-
Sometimes this capability is useful. However, in general, you should avoid it, because it
3750-
couples the code to Spring and does not follow the Inversion of Control style, where
3751-
collaborators are provided to beans as properties. Other methods of the
3752-
`ApplicationContext` provide access to file resources, publishing application events, and
3753-
accessing a `MessageSource`. These additional features are described in
3749+
Sometimes this capability is useful. However, in general, you should avoid it, because
3750+
it couples the code to Spring and does not follow the Inversion of Control style,
3751+
where collaborators are provided to beans as properties. Other methods of the
3752+
`ApplicationContext` provide access to file resources, publishing application events,
3753+
and accessing a `MessageSource`. These additional features are described in
37543754
<<context-introduction>>.
37553755

37563756
As of Spring 2.5, autowiring is another alternative to obtain a reference to the
3757-
`ApplicationContext`. The "`traditional`" `constructor` and `byType` autowiring modes (as
3758-
described in <<beans-factory-autowire>>) can provide a dependency of type
3757+
`ApplicationContext`. The "`traditional`" `constructor` and `byType` autowiring modes
3758+
(as described in <<beans-factory-autowire>>) can provide a dependency of type
37593759
`ApplicationContext` for a constructor argument or a setter method parameter,
37603760
respectively. For more flexibility, including the ability to autowire fields and
37613761
multiple parameter methods, use the new annotation-based autowiring features. If you do,
@@ -3789,11 +3789,10 @@ init-method.
37893789
[[aware-list]]
37903790
=== Other `Aware` Interfaces
37913791

3792-
Besides `ApplicationContextAware` and `BeanNameAware` (discussed
3793-
<<beans-factory-aware,earlier>>), Spring offers a range of `Aware` interfaces that let
3794-
beans indicate to the container that they require a certain infrastructure dependency. As
3795-
a general rule, the name is a good indication of the dependency type. The following table
3796-
summarizes the most important `Aware` interfaces:
3792+
Besides `ApplicationContextAware` and `BeanNameAware` (discussed <<beans-factory-aware,earlier>>),
3793+
Spring offers a wide range of `Aware` callback interfaces that let beans indicate to the container
3794+
that they require a certain infrastructure dependency. As a general rule, the name indicates the
3795+
dependency type. The following table summarizes the most important `Aware` interfaces:
37973796

37983797
[[beans-factory-nature-aware-list]]
37993798
.Aware interfaces
@@ -3822,7 +3821,7 @@ summarizes the most important `Aware` interfaces:
38223821

38233822
| `BootstrapContextAware`
38243823
| Resource adapter `BootstrapContext` the container runs in. Typically available only in
3825-
JCA aware `ApplicationContext` instances.
3824+
JCA-aware `ApplicationContext` instances.
38263825
| <<integration.adoc#cci, JCA CCI>>
38273826

38283827
| `LoadTimeWeaverAware`
@@ -9336,19 +9335,18 @@ specific and appropriate to the actual application context type.
93369335

93379336
You can configure a bean deployed into the application context to implement the special
93389337
callback interface, `ResourceLoaderAware`, to be automatically called back at
9339-
initialization time with the application context itself passed in as the
9340-
`ResourceLoader`. You can also expose properties of type `Resource`, to be used to
9341-
access static resources. They are injected into it like any other properties. You
9342-
can specify those `Resource` properties as simple `String` paths and rely on a special
9343-
JavaBean `PropertyEditor` (which is automatically registered by the context) to convert
9344-
those text strings to actual `Resource` objects when the bean is deployed.
9338+
initialization time with the application context itself passed in as the `ResourceLoader`.
9339+
You can also expose properties of type `Resource`, to be used to access static resources.
9340+
They are injected into it like any other properties. You can specify those `Resource`
9341+
properties as simple `String` paths and rely on automatic conversion from those text
9342+
strings to actual `Resource` objects when the bean is deployed.
93459343

93469344
The location path or paths supplied to an `ApplicationContext` constructor are actually
9347-
resource strings and, in simple form, are treated appropriately according to the specific context
9348-
implementation. For example `ClassPathXmlApplicationContext` treats a simple location path as a
9349-
classpath location. You can also use location paths (resource strings) with special
9350-
prefixes to force loading of definitions from the classpath or a URL, regardless of the
9351-
actual context type.
9345+
resource strings and, in simple form, are treated appropriately according to the specific
9346+
context implementation. For example `ClassPathXmlApplicationContext` treats a simple
9347+
location path as a classpath location. You can also use location paths (resource strings)
9348+
with special prefixes to force loading of definitions from the classpath or a URL,
9349+
regardless of the actual context type.
93529350

93539351

93549352

src/docs/asciidoc/core/core-resources.adoc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ The following table summarizes the strategy for converting `String` objects to `
323323
[[resources-resourceloaderaware]]
324324
== The `ResourceLoaderAware` interface
325325

326-
The `ResourceLoaderAware` interface is a special marker interface that identifies objects
327-
that expect to be provided with a `ResourceLoader` reference. The following listing shows
328-
the definition of the `ResourceLoaderAware` interface:
326+
The `ResourceLoaderAware` interface is a special callback interface which identifies
327+
components that expect to be provided with a `ResourceLoader` reference. The following
328+
listing shows the definition of the `ResourceLoaderAware` interface:
329329

330330
====
331331
[source,java,indent=0]
@@ -338,29 +338,29 @@ the definition of the `ResourceLoaderAware` interface:
338338
----
339339
====
340340

341-
When a class implements `ResourceLoaderAware` and is deployed into an application
342-
context (as a Spring-managed bean), it is recognized as `ResourceLoaderAware` by the
343-
application context. The application context then invokes
344-
`setResourceLoader(ResourceLoader)`, supplying itself as the argument (remember, all
345-
application contexts in Spring implement the `ResourceLoader` interface).
341+
When a class implements `ResourceLoaderAware` and is deployed into an application context
342+
(as a Spring-managed bean), it is recognized as `ResourceLoaderAware` by the application
343+
context. The application context then invokes `setResourceLoader(ResourceLoader)`,
344+
supplying itself as the argument (remember, all application contexts in Spring implement
345+
the `ResourceLoader` interface).
346346

347-
Since an `ApplicationContext` is a `ResourceLoader`, the bean could also
348-
implement the `ApplicationContextAware` interface and use the supplied application
349-
context directly to load resources. However, in general, it is better to use the specialized
350-
`ResourceLoader` interface if that is all you need. The code would be coupled only
351-
to the resource loading interface (which can be considered a utility interface) and not to
352-
the whole Spring `ApplicationContext` interface.
347+
Since an `ApplicationContext` is a `ResourceLoader`, the bean could also implement the
348+
`ApplicationContextAware` interface and use the supplied application context directly to
349+
load resources. However, in general, it is better to use the specialized `ResourceLoader`
350+
interface if that is all you need. The code would be coupled only to the resource loading
351+
interface (which can be considered a utility interface) and not to the whole Spring
352+
`ApplicationContext` interface.
353353

354354
As of Spring 2.5, you can rely upon autowiring of the `ResourceLoader` as an alternative
355355
to implementing the `ResourceLoaderAware` interface. The "`traditional`" `constructor` and
356-
`byType` autowiring modes (as described in <<beans-factory-autowire>>) are now capable
357-
of providing a dependency of type `ResourceLoader` for either a constructor argument or a
356+
`byType` autowiring modes (as described in <<beans-factory-autowire>>) are now capable of
357+
providing a dependency of type `ResourceLoader` for either a constructor argument or a
358358
setter method parameter, respectively. For more flexibility (including the ability to
359359
autowire fields and multiple parameter methods), consider using the annotation-based
360360
autowiring features. In that case, the `ResourceLoader` is autowired into a field,
361-
constructor argument, or method parameter that expects the `ResourceLoader` type as
362-
long as the field, constructor, or method in question carries the `@Autowired`
363-
annotation. For more information, see <<beans-autowired-annotation>>.
361+
constructor argument, or method parameter that expects the `ResourceLoader` type as long
362+
as the field, constructor, or method in question carries the `@Autowired` annotation.
363+
For more information, see <<beans-autowired-annotation>>.
364364

365365

366366

0 commit comments

Comments
 (0)