Skip to content

Commit 1741b6d

Browse files
committed
Merge branch '5.1.x'
2 parents 383f18e + 95232d5 commit 1741b6d

File tree

5 files changed

+44
-24
lines changed

5 files changed

+44
-24
lines changed

spring-test/spring-test.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ dependencies {
7272
testCompile("org.apache.tiles:tiles-core:${tiles3Version}", withoutJclOverSlf4J)
7373
testCompile("org.apache.tiles:tiles-servlet:${tiles3Version}", withoutJclOverSlf4J)
7474
testCompile("org.hsqldb:hsqldb:${hsqldbVersion}")
75-
testCompile("org.apache.httpcomponents:httpclient:4.5.7") {
75+
testCompile("org.apache.httpcomponents:httpclient:4.5.8") {
7676
exclude group: "commons-logging", module: "commons-logging"
7777
}
7878
testCompile("io.projectreactor.netty:reactor-netty")

spring-web/spring-web.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ dependencies {
3737
optional("org.eclipse.jetty:jetty-servlet") {
3838
exclude group: "javax.servlet", module: "javax.servlet-api"
3939
}
40-
optional("org.eclipse.jetty:jetty-reactive-httpclient:1.0.2")
40+
optional("org.eclipse.jetty:jetty-reactive-httpclient:1.0.3")
4141
optional("com.squareup.okhttp3:okhttp:3.14.0")
42-
optional("org.apache.httpcomponents:httpclient:4.5.7") {
42+
optional("org.apache.httpcomponents:httpclient:4.5.8") {
4343
exclude group: "commons-logging", module: "commons-logging"
4444
}
4545
optional("org.apache.httpcomponents:httpasyncclient:4.1.4") {

spring-webflux/spring-webflux.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies {
3535
optional("io.undertow:undertow-websockets-jsr:${undertowVersion}") {
3636
exclude group: "org.jboss.spec.javax.websocket", module: "jboss-websocket-api_1.1_spec"
3737
}
38-
optional("org.apache.httpcomponents:httpclient:4.5.7") {
38+
optional("org.apache.httpcomponents:httpclient:4.5.8") {
3939
exclude group: "commons-logging", module: "commons-logging"
4040
}
4141
optional("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
@@ -53,7 +53,7 @@ dependencies {
5353
testCompile("org.apache.tomcat:tomcat-util:${tomcatVersion}")
5454
testCompile("org.eclipse.jetty:jetty-server")
5555
testCompile("org.eclipse.jetty:jetty-servlet")
56-
testCompile("org.eclipse.jetty:jetty-reactive-httpclient:1.0.2")
56+
testCompile("org.eclipse.jetty:jetty-reactive-httpclient:1.0.3")
5757
testCompile("com.squareup.okhttp3:mockwebserver:3.14.0")
5858
testCompile("org.jetbrains.kotlin:kotlin-script-runtime:${kotlinVersion}")
5959
testCompile(project(":spring-core-coroutines"))

spring-webmvc/spring-webmvc.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ dependencies {
5050
testCompile("org.eclipse.jetty:jetty-server") {
5151
exclude group: "javax.servlet", module: "javax.servlet"
5252
}
53-
testCompile("org.apache.httpcomponents:httpclient:4.5.7") {
53+
testCompile("org.apache.httpcomponents:httpclient:4.5.8") {
5454
exclude group: "commons-logging", module: "commons-logging"
5555
}
5656
testCompile("commons-fileupload:commons-fileupload:1.4")

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

+38-18
Original file line numberDiff line numberDiff line change
@@ -4425,9 +4425,9 @@ implementation type, consider declaring the most specific return type on your fa
44254425
method (at least as specific as required by the injection points referring to your bean).
44264426
====
44274427

4428-
You can also provide all beans of a particular type from the
4429-
`ApplicationContext` by adding the annotation to a field or method that expects an array
4430-
of that type, as the following example shows:
4428+
You can also provide all beans of a particular type from the `ApplicationContext`
4429+
by adding the annotation to a field or method that expects an array of that type,
4430+
as the following example shows:
44314431

44324432
[source,java,indent=0]
44334433
[subs="verbatim,quotes"]
@@ -4477,8 +4477,8 @@ Note that the standard `javax.annotation.Priority` annotation is not available a
44774477
through `@Order` values in combination with `@Primary` on a single bean for each type.
44784478
====
44794479

4480-
Even typed `Map` instances can be autowired as long as the expected key type is `String`. The Map
4481-
values contain all beans of the expected type, and the keys contain the
4480+
Even typed `Map` instances can be autowired as long as the expected key type is `String`.
4481+
The Map values contain all beans of the expected type, and the keys contain the
44824482
corresponding bean names, as the following example shows:
44834483

44844484
[source,java,indent=0]
@@ -4497,10 +4497,14 @@ corresponding bean names, as the following example shows:
44974497
}
44984498
----
44994499

4500-
By default, the autowiring fails whenever zero candidate beans are available. The
4501-
default behavior is to treat annotated methods, constructors, and fields as
4502-
indicating required dependencies. You can change this behavior as demonstrated, in the
4503-
following example:
4500+
By default, autowiring fails when no matching candidate beans are available for
4501+
a given injection point. In the case of a declared array, collection or map,
4502+
at least one matching element is expected.
4503+
4504+
The default behavior is to treat annotated methods and fields as indicating
4505+
required dependencies. You can change this behavior as demonstrated in the
4506+
following example, enabling the framework to skip a non-satisfiable injection
4507+
point through marking it as non-required:
45044508

45054509
[source,java,indent=0]
45064510
[subs="verbatim,quotes"]
@@ -4518,18 +4522,34 @@ following example:
45184522
}
45194523
----
45204524

4525+
A non-required method will not be called at all if its dependency (or one of its
4526+
dependencies in case of multiple arguments) is not available. A non-required field
4527+
will not get populated at all in such case, leaving its default value in place.
4528+
4529+
Injected constructor and factory method arguments are a special case since the
4530+
'required' flag on `@Autowired` has a somewhat different meaning due to Spring's
4531+
constructor resolution algorithm potentially dealing with multiple constructors.
4532+
Constructor and factory method arguments are effectively required by default but
4533+
with a few special rules in a single-constructor scenario, such as multi-element
4534+
injection points (arrays, collections, maps) resolving to empty instances if no
4535+
matching beans are available. This allows for a common implementation pattern
4536+
where all dependencies can be declared in a unique multi-argument constructor,
4537+
e.g. declared as a single public constructor without an `@Autowired` annotation.
4538+
45214539
[NOTE]
45224540
====
4523-
Only one annotated constructor per-class can be marked as required, but multiple
4524-
non-required constructors can be annotated. In that case, each is considered among the
4525-
candidates and Spring uses the greediest constructor whose dependencies can be
4541+
Only one annotated constructor per class can be marked as required, but multiple
4542+
non-required constructors can be annotated. In that case, each is considered among
4543+
the candidates and Spring uses the greediest constructor whose dependencies can be
45264544
satisfied -- that is, the constructor that has the largest number of arguments.
4527-
4528-
The required attribute of `@Autowired` is recommended over the `@Required` annotation.
4529-
The required attribute indicates that the property is not required for autowiring
4530-
purposes. The property is ignored if it cannot be autowired. `@Required`, on the other
4531-
hand, is stronger in that it enforces the property that was set by any means supported
4532-
by the container. If no value is injected, a corresponding exception is raised.
4545+
The constructor resolution algorithm is the same as for non-annotated classes with
4546+
overloaded constructors, just narrowing the candidates to annotated constructors.
4547+
4548+
The 'required' attribute of `@Autowired` is recommended over the `@Required` annotation
4549+
on setter methods. The 'required' attribute indicates that the property is not required
4550+
for autowiring purposes. The property is ignored if it cannot be autowired. `@Required`,
4551+
on the other hand, is stronger in that it enforces the property to be set by any means
4552+
supported by the container. If no value is defined, a corresponding exception is raised.
45334553
====
45344554

45354555
Alternatively, you can express the non-required nature of a particular dependency

0 commit comments

Comments
 (0)