Skip to content

Commit 395e3d0

Browse files
Jay Bryantbclozel
authored andcommitted
Edit the core content reference documentation
I edited for the usual stuff: spelling, punctuation, grammar, formatting, usage, and voice.
1 parent d0ada56 commit 395e3d0

File tree

9 files changed

+3541
-2882
lines changed

9 files changed

+3541
-2882
lines changed

src/docs/asciidoc/core/core-aop-api.adoc

Lines changed: 560 additions & 520 deletions
Large diffs are not rendered by default.

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

Lines changed: 1239 additions & 1051 deletions
Large diffs are not rendered by default.

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

Lines changed: 391 additions & 270 deletions
Large diffs are not rendered by default.

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[[beans]]
2-
= The IoC container
2+
= The IoC Container
33

4+
This chapter covers Spring's Inversion of Control (IoC) container.
45

56

67

@@ -143,7 +144,7 @@ The following example shows the basic structure of XML-based configuration metad
143144
xsi:schemaLocation="http://www.springframework.org/schema/beans
144145
http://www.springframework.org/schema/beans/spring-beans.xsd">
145146
146-
<bean id="..." class="..."> <1> <2>
147+
<bean id="..." class="..."> <1> <2>
147148
<!-- collaborators and configuration for this bean go here -->
148149
</bean>
149150
@@ -2136,6 +2137,7 @@ modes:
21362137

21372138
[[beans-factory-autowiring-modes-tbl]]
21382139
.Autowiring modes
2140+
[cols="20%,80%"]
21392141
|===
21402142
| Mode| Explanation
21412143

@@ -2568,6 +2570,7 @@ The following table describes the supported scopes:
25682570

25692571
[[beans-factory-scopes-tbl]]
25702572
.Bean scopes
2573+
[cols="20%,80%"]
25712574
|===
25722575
| Scope| Description
25732576

@@ -2957,7 +2960,7 @@ understand the "`why`" as well as the "`how`" behind it:
29572960
<!-- an HTTP Session-scoped bean exposed as a proxy -->
29582961
<bean id="userPreferences" class="com.something.UserPreferences" scope="session">
29592962
<!-- instructs the container to proxy the surrounding bean -->
2960-
<aop:scoped-proxy/> <1>
2963+
<aop:scoped-proxy/> <1>
29612964
</bean>
29622965
29632966
<!-- a singleton-scoped bean injected with a proxy to the above bean -->
@@ -4565,7 +4568,7 @@ references and values even when you use the class outside of a container.
45654568

45664569

45674570
[[beans-autowired-annotation]]
4568-
=== @Autowired
4571+
=== Using `@Autowired`
45694572

45704573
NOTE: JSR 330's `@Inject` annotation can be used in place of Spring's `@Autowired` annotation
45714574
in the examples included in this section. See <<beans-standard-annotations,here>> for more details.
@@ -5007,13 +5010,13 @@ The following example shows corresponding bean definitions.
50075010
<context:annotation-config/>
50085011
50095012
<bean class="example.SimpleMovieCatalog">
5010-
<qualifier value="main"/> <1>
5013+
<qualifier value="main"/> <1>
50115014
50125015
<!-- inject any dependencies required by this bean -->
50135016
</bean>
50145017
50155018
<bean class="example.SimpleMovieCatalog">
5016-
<qualifier value="action"/> <2>
5019+
<qualifier value="action"/> <2>
50175020
50185021
<!-- inject any dependencies required by this bean -->
50195022
</bean>
@@ -5201,7 +5204,7 @@ following example:
52015204
public class MovieRecommender {
52025205
52035206
@Autowired
5204-
@Offline <1>
5207+
@Offline <1>
52055208
private MovieCatalog offlineCatalog;
52065209
52075210
// ...
@@ -5217,7 +5220,7 @@ Now the bean definition only needs a qualifier `type`, as shown in the following
52175220
[subs="verbatim,quotes"]
52185221
----
52195222
<bean class="example.SimpleMovieCatalog">
5220-
<qualifier type="Offline"/> <1>
5223+
<qualifier type="Offline"/> <1>
52215224
<!-- inject any dependencies required by this bean -->
52225225
</bean>
52235226
----
@@ -5459,7 +5462,7 @@ demonstrated in the following example:
54595462
54605463
private MovieFinder movieFinder;
54615464
5462-
@Resource(name="myMovieFinder") <1>
5465+
@Resource(name="myMovieFinder") <1>
54635466
public void setMovieFinder(MovieFinder movieFinder) {
54645467
this.movieFinder = movieFinder;
54655468
}
@@ -5516,7 +5519,7 @@ named customerPreferenceDao and then falls back to a primary type match for the
55165519
private CustomerPreferenceDao customerPreferenceDao;
55175520
55185521
@Resource
5519-
private ApplicationContext context; <1>
5522+
private ApplicationContext context; <1>
55205523
55215524
public MovieRecommender() {
55225525
}
@@ -5630,7 +5633,7 @@ annotation. For example, the `@Service` annotation mentioned <<beans-stereotype-
56305633
@Target(ElementType.TYPE)
56315634
@Retention(RetentionPolicy.RUNTIME)
56325635
@Documented
5633-
@Component <1>
5636+
@Component <1>
56345637
public @interface Service {
56355638
56365639
// ....
@@ -8181,7 +8184,7 @@ the following example shows:
81818184
public class AppConfig {
81828185
81838186
@Bean("dataSource")
8184-
@Profile("development") <1>
8187+
@Profile("development") <1>
81858188
public DataSource standaloneDataSource() {
81868189
return new EmbeddedDatabaseBuilder()
81878190
.setType(EmbeddedDatabaseType.HSQL)
@@ -8191,14 +8194,15 @@ the following example shows:
81918194
}
81928195
81938196
@Bean("dataSource")
8194-
**@Profile("production")**
8197+
@Profile("production") <2>
81958198
public DataSource jndiDataSource() throws Exception {
81968199
Context ctx = new InitialContext();
81978200
return (DataSource) ctx.lookup("java:comp/env/jdbc/datasource");
81988201
}
81998202
}
82008203
----
82018204
<1> The `standaloneDataSource` method is available only in the `development` profile.
8205+
<2> The `jndiDataSource` method is available only in the `production` profile.
82028206
====
82038207

82048208
[NOTE]
@@ -8895,6 +8899,7 @@ The following table describes the standard events that Spring provides:
88958899

88968900
[[beans-ctx-events-tbl]]
88978901
.Built-in Events
8902+
[cols="30%,70%"]
88988903
|===
88998904
| Event| Explanation
89008905

@@ -9460,6 +9465,7 @@ The following table lists features provided by the `BeanFactory` and
94609465

94619466
[[context-introduction-ctx-vs-beanfactory-feature-matrix]]
94629467
.Feature Matrix
9468+
[cols="50%,25%,25%"]
94639469
|===
94649470
| Feature | `BeanFactory` | `ApplicationContext`
94659471

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,107 @@
11
[[databuffers]]
22
= Data Buffers and Codecs
33

4-
5-
6-
7-
== Introduction
8-
94
The `DataBuffer` interface defines an abstraction over byte buffers.
10-
The main reason for introducing it, and not use the standard `java.nio.ByteBuffer` instead, is Netty.
11-
Netty does not use `ByteBuffer`, but instead offers `ByteBuf` as an alternative.
5+
The main reason for introducing it (and not using the standard `java.nio.ByteBuffer` instead) is Netty.
6+
Netty does not use `ByteBuffer` but instead offers `ByteBuf` as an alternative.
127
Spring's `DataBuffer` is a simple abstraction over `ByteBuf` that can also be used on non-Netty
13-
platforms (i.e. Servlet 3.1+).
14-
8+
platforms (that is, Servlet 3.1+).
159

1610

1711

1812
== `DataBufferFactory`
1913

20-
The `DataBufferFactory` offers functionality to allocate new data buffers, as well as to wrap
14+
The `DataBufferFactory` offers functionality to allocate new data buffers as well as to wrap
2115
existing data.
22-
The `allocate` methods allocate a new data buffer, with a default or given capacity.
23-
Though `DataBuffer` implementation grow and shrink on demand, it is more efficient to give the
16+
The `allocateBuffer` methods allocate a new data buffer with a default or given capacity.
17+
Though `DataBuffer` implementations grow and shrink on demand, it is more efficient to give the
2418
capacity upfront, if known.
2519
The `wrap` methods decorate an existing `ByteBuffer` or byte array.
26-
Wrapping does not involve allocation: it simply decorates the given data with a `DataBuffer`
20+
Wrapping does not involve allocation. It decorates the given data with a `DataBuffer`
2721
implementation.
2822

29-
There are two implementation of `DataBufferFactory`: the `NettyDataBufferFactory` which is meant
30-
to be used on Netty platforms, such as Reactor Netty.
31-
The other implementation, the `DefaultDataBufferFactory`, is used on other platforms, such as
32-
Servlet 3.1+ servers.
33-
23+
There are two implementation of `DataBufferFactory`: the `NettyDataBufferFactory`
24+
(for Netty platforms, such as Reactor Netty) and
25+
`DefaultDataBufferFactory` (for other platforms, such as
26+
Servlet 3.1+ servers).
3427

3528

3629

37-
== The `DataBuffer` interface
30+
== The `DataBuffer` Interface
3831

39-
The `DataBuffer` interface is similar to `ByteBuffer`, but offers a number of advantages.
32+
The `DataBuffer` interface is similar to `ByteBuffer` but offers a number of advantages.
4033
Similar to Netty's `ByteBuf`, the `DataBuffer` abstraction offers independent read and write
4134
positions.
42-
This is different from the JDK's `ByteBuffer`, which only exposes one position for both reading and
43-
writing, and a separate `flip()` operation to switch between the two I/O operations.
35+
This is different from the JDK's `ByteBuffer`, which exposes only one position for both reading and
36+
writing and a separate `flip()` operation to switch between the two I/O operations.
4437
In general, the following invariant holds for the read position, write position, and the capacity:
4538

39+
====
4640
[literal]
4741
[subs="verbatim,quotes"]
4842
--
4943
0 <= read position <= write position <= capacity
5044
--
45+
====
5146

5247
When reading bytes from the `DataBuffer`, the read position is automatically updated in accordance with
5348
the amount of data read from the buffer.
5449
Similarly, when writing bytes to the `DataBuffer`, the write position is updated with the amount of
5550
data written to the buffer.
56-
Also, when writing data, the capacity of a `DataBuffer` is automatically expanded, just like `StringBuilder`,
51+
Also, when writing data, the capacity of a `DataBuffer` is automatically expanded, in the same fashion as `StringBuilder`,
5752
`ArrayList`, and similar types.
5853

5954
Besides the reading and writing functionality mentioned above, the `DataBuffer` also has methods to
60-
view a (slice of a) buffer as `ByteBuffer`, `InputStream`, or `OutputStream`.
55+
view a (slice of a) buffer as a `ByteBuffer`, an `InputStream`, or an `OutputStream`.
6156
Additionally, it offers methods to determine the index of a given byte.
6257

63-
There are two implementation of `DataBuffer`: the `NettyDataBuffer` which is meant to be used on
64-
Netty platforms, such as Reactor Netty.
65-
The other implementation, the `DefaultDataBuffer`, is used on other platforms, such as Servlet 3.1+
66-
servers.
58+
As mentioned earlier, there are two implementation of `DataBufferFactory`: the `NettyDataBufferFactory`
59+
(for Netty platforms, such as Reactor Netty) and
60+
`DefaultDataBufferFactory` (for other platforms, such as
61+
Servlet 3.1+ servers).
6762

6863

6964

7065
=== `PooledDataBuffer`
7166

7267
The `PooledDataBuffer` is an extension to `DataBuffer` that adds methods for reference counting.
7368
The `retain` method increases the reference count by one.
74-
The `release` method decreases the count by one, and releases the buffer's memory when the count
69+
The `release` method decreases the count by one and releases the buffer's memory when the count
7570
reaches 0.
76-
Both of these methods are related to _reference counting_, a mechanism that is explained below.
71+
Both of these methods are related to reference counting, a mechanism that we explain <<databuffer-reference-counting,later>>.
7772

7873
Note that `DataBufferUtils` offers useful utility methods for releasing and retaining pooled data
7974
buffers.
80-
These methods take a plain `DataBuffer` as parameter, but only call `retain` or `release` if the
75+
These methods take a plain `DataBuffer` as a parameter but only call `retain` or `release` if the
8176
passed data buffer is an instance of `PooledDataBuffer`.
8277

8378

8479
[[databuffer-reference-counting]]
8580
==== Reference Counting
8681

87-
Reference counting is not a common technique in Java; it is much more common in other programming
88-
languages such as Object C and C++.
89-
In and of itself, reference counting is not complex: it basically involves tracking the number of
82+
Reference counting is not a common technique in Java. It is much more common in other programming
83+
languages, such as Object C and C++.
84+
In and of itself, reference counting is not complex. It basically involves tracking the number of
9085
references that apply to an object.
9186
The reference count of a `PooledDataBuffer` starts at 1, is incremented by calling `retain`,
92-
and decremented by calling `release`.
93-
As long as the buffer's reference count is larger than 0 the buffer will not be released.
94-
When the number decreases to 0, the instance will be released.
95-
In practice, this means that the reserved memory captured by the buffer will be returned back to
87+
and is decremented by calling `release`.
88+
As long as the buffer's reference count is larger than 0, the buffer is not released.
89+
When the number decreases to 0, the instance is released.
90+
In practice, this means that the reserved memory captured by the buffer is returned back to
9691
the memory pool, ready to be used for future allocations.
9792

98-
In general, _the last component to access a `DataBuffer` is responsible for releasing it_.
93+
In general, the last component to access a `DataBuffer` is responsible for releasing it.
9994
Within Spring, there are two sorts of components that release buffers: decoders and transports.
100-
Decoders are responsible for transforming a stream of buffers into other types (see <<codecs>> below),
101-
and transports are responsible for sending buffers across a network boundary, typically as an HTTP message.
102-
This means that if you allocate data buffers for the purpose of putting them into an outbound HTTP
103-
message (i.e. client-side request or server-side response), they do not have to be released.
95+
Decoders are responsible for transforming a stream of buffers into other types (see <<codecs>>),
96+
and transports are responsible for sending buffers across a network boundary, typically as an HTTP message.
97+
This means that, if you allocate data buffers for the purpose of putting them into an outbound HTTP
98+
message (that is, a client-side request or server-side response), they do not have to be released.
10499
The other consequence of this rule is that if you allocate data buffers that do not end up in the
105-
body, for instance because of a thrown exception, you will have to release them yourself.
100+
body (for instance, because of a thrown exception), you have to release them yourself.
106101
The following snippet shows a typical `DataBuffer` usage scenario when dealing with methods that
107102
throw exceptions:
108103

104+
====
109105
[source,java,indent=0]
110106
[subs="verbatim,quotes"]
111107
----
@@ -130,46 +126,49 @@ throw exceptions:
130126
131127
<1> A new buffer is allocated.
132128
<2> A boolean flag indicates whether the allocated buffer should be released.
133-
<3> This example method loads data into the buffer. Note that the method can throw an `IOException`,
134-
and therefore a `finally` block to release the buffer is required.
135-
<4> If no exception occurred, we switch the `release` flag to `false` as the buffer will now be
129+
<3> This example method loads data into the buffer. Note that the method can throw an `IOException`.
130+
Therefore, a `finally` block to release the buffer is required.
131+
<4> If no exception occurred, we switch the `release` flag to `false` as the buffer is now
136132
released as part of sending the HTTP body across the wire.
137-
<5> If an exception did occur, the flag is still set to `true`, and the buffer will be released
133+
<5> If an exception did occur, the flag is still set to `true`, and the buffer is released
138134
here.
135+
====
139136

140137

141138

142-
=== DataBufferUtils
139+
=== `DataBufferUtils`
143140

144-
`DataBufferUtils` contains various utility methods that operate on data buffers.
141+
The `DataBufferUtils` class contains various utility methods that operate on data buffers.
145142
It contains methods for reading a `Flux` of `DataBuffer` objects from an `InputStream` or NIO
146-
`Channel`, and methods for writing a data buffer `Flux` to an `OutputStream` or `Channel`.
143+
`Channel` and methods for writing a data buffer `Flux` to an `OutputStream` or `Channel`.
147144
`DataBufferUtils` also exposes `retain` and `release` methods that operate on plain `DataBuffer`
148145
instances (so that casting to a `PooledDataBuffer` is not required).
149146

150147
Additionally, `DataBufferUtils` exposes `compose`, which merges a stream of data buffers into one.
151148
For instance, this method can be used to convert the entire HTTP body into a single buffer (and
152-
from that, a `String`, or `InputStream`).
149+
from that, a `String` or `InputStream`).
153150
This is particularly useful when dealing with older, blocking APIs.
154151
Note, however, that this puts the entire body in memory, and therefore uses more memory than a pure
155152
streaming solution would.
156153

157-
[codecs]
154+
155+
156+
[[codecs]]
158157
== Codecs
159158

160159
The `org.springframework.core.codec` package contains the two main abstractions for converting a
161-
stream of bytes into a stream of objects, or vice-versa.
160+
stream of bytes into a stream of objects or vice-versa.
162161
The `Encoder` is a strategy interface that encodes a stream of objects into an output stream of
163162
data buffers.
164-
The `Decoder` does the reverse: it turns a stream of data buffers into a stream of objects.
165-
Note that a decoder instance needs to consider <<databuffer-reference-counting, reference counting>>.
163+
The `Decoder` does the reverse: It turns a stream of data buffers into a stream of objects.
164+
Note that a decoder instance needs to consider <<databuffer-reference-counting,reference counting>>.
166165

167-
Spring comes with a wide array of default codecs, capable of converting from/to `String`,
168-
`ByteBuffer`, byte arrays, and also codecs that support marshalling libraries such as JAXB and
166+
Spring comes with a wide array of default codecs (to convert from and to `String`,
167+
`ByteBuffer`, and byte arrays) and codecs that support marshalling libraries such as JAXB and
169168
Jackson (with https://github.com/FasterXML/jackson-core/issues/57[Jackson 2.9+ support for non-blocking parsing]).
170169
Within the context of Spring WebFlux, codecs are used to convert the request body into a
171-
`@RequestMapping` parameter, or to convert the return type into the response body that is sent back
170+
`@RequestMapping` parameter or to convert the return type into the response body that is sent back
172171
to the client.
173-
The default codecs are configured in the `WebFluxConfigurationSupport` class, and can easily be
174-
changed by overriding the `configureHttpMessageCodecs` when inheriting from that class.
175-
For more information about using codecs in WebFlux, see <<web-reactive#webflux-codecs, this section>>.
172+
The default codecs are configured in the `WebFluxConfigurationSupport` class. You can
173+
change them by overriding the `configureHttpMessageCodecs` when you inherit from that class.
174+
For more information about using codecs in WebFlux, see <<web-reactive#webflux-codecs>>.

0 commit comments

Comments
 (0)