Skip to content

Commit f1a1190

Browse files
committed
Merge branch '6.1.x'
# Conflicts: # framework-docs/modules/ROOT/pages/data-access/transaction/declarative/annotations.adoc
2 parents 35c183d + cbda469 commit f1a1190

File tree

6 files changed

+68
-16
lines changed

6 files changed

+68
-16
lines changed

framework-docs/modules/ROOT/pages/core/beans/definition.adoc

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ For details about the mechanism for supplying arguments to the constructor (if r
250250
and setting object instance properties after the object is constructed, see
251251
xref:core/beans/dependencies/factory-collaborators.adoc[Injecting Dependencies].
252252

253+
NOTE: In the case of constructor arguments, the container can select a corresponding
254+
constructor among several overloaded constructors. That said, to avoid ambiguities,
255+
it is recommended to keep your constructor signatures as straightforward as possible.
256+
253257

254258
[[beans-factory-class-static-factory-method]]
255259
=== Instantiation with a Static Factory Method
@@ -310,6 +314,24 @@ For details about the mechanism for supplying (optional) arguments to the factor
310314
and setting object instance properties after the object is returned from the factory,
311315
see xref:core/beans/dependencies/factory-properties-detailed.adoc[Dependencies and Configuration in Detail].
312316

317+
NOTE: In the case of factory method arguments, the container can select a corresponding
318+
method among several overloaded methods of the same name. That said, to avoid ambiguities,
319+
it is recommended to keep your factory method signatures as straightforward as possible.
320+
321+
[TIP]
322+
====
323+
A typical problematic case with factory method overloading is Mockito with its many
324+
overloads of the `mock` method. Choose the most specific variant of `mock` possible:
325+
326+
[source,xml,indent=0,subs="verbatim,quotes"]
327+
----
328+
<bean id="clientService" class="org.mockito.Mockito" factory-method="mock">
329+
<constructor-arg type="java.lang.Class" value="examples.ClientService"/>
330+
<constructor-arg type="java.lang.String" value="clientService"/>
331+
</bean>
332+
----
333+
====
334+
313335

314336
[[beans-factory-class-instance-factory-method]]
315337
=== Instantiation by Using an Instance Factory Method
@@ -432,8 +454,8 @@ Kotlin::
432454
======
433455

434456
This approach shows that the factory bean itself can be managed and configured through
435-
dependency injection (DI). See xref:core/beans/dependencies/factory-properties-detailed.adoc[Dependencies and Configuration in Detail]
436-
.
457+
dependency injection (DI).
458+
See xref:core/beans/dependencies/factory-properties-detailed.adoc[Dependencies and Configuration in Detail].
437459

438460
NOTE: In Spring documentation, "factory bean" refers to a bean that is configured in the
439461
Spring container and that creates objects through an
@@ -460,5 +482,3 @@ cases into account and returns the type of object that a `BeanFactory.getBean` c
460482
going to return for the same bean name.
461483

462484

463-
464-

framework-docs/modules/ROOT/pages/data-access/transaction/declarative/annotations.adoc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ Kotlin::
7474
----
7575
======
7676

77-
Used at the class level as above, the annotation indicates a default for all methods of
78-
the declaring class (as well as its subclasses). Alternatively, each method can be
79-
annotated individually. See xref:data-access/transaction/declarative/annotations.adoc#transaction-declarative-annotations-method-visibility[method visibility] for
80-
further details on which methods Spring considers transactional. Note that a class-level
77+
Used at the class level as above, the annotation indicates a default for all methods
78+
of the declaring class (as well as its subclasses). Alternatively, each method can be
79+
annotated individually. See
80+
xref:data-access/transaction/declarative/annotations.adoc#transaction-declarative-annotations-method-visibility[method visibility]
81+
for further details on which methods Spring considers transactional. Note that a class-level
8182
annotation does not apply to ancestor classes up the class hierarchy; in such a scenario,
8283
inherited methods need to be locally redeclared in order to participate in a
8384
subclass-level annotation.
@@ -436,7 +437,8 @@ properties of the `@Transactional` annotation:
436437
| Optional array of exception name patterns that must not cause rollback.
437438
|===
438439

439-
TIP: See xref:data-access/transaction/declarative/rolling-back.adoc#transaction-declarative-rollback-rules[Rollback rules]
440+
TIP: See
441+
xref:data-access/transaction/declarative/rolling-back.adoc#transaction-declarative-rollback-rules[Rollback rules]
440442
for further details on rollback rule semantics, patterns, and warnings
441443
regarding possible unintentional matches for pattern-based rollback rules.
442444

framework-docs/modules/ROOT/pages/data-access/transaction/declarative/rolling-back.adoc

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Vavr's `Try` method to trigger transaction rollbacks when it returns a 'Failure'
2424
This allows you to handle functional-style errors using Try and have the transaction
2525
automatically rolled back in case of a failure. For more information on Vavr's Try,
2626
refer to the https://docs.vavr.io/#_try[official Vavr documentation].
27-
2827
Here's an example of how to use Vavr's Try with a transactional method:
28+
2929
[tabs]
3030
======
3131
Java::
@@ -42,6 +42,32 @@ Java::
4242
----
4343
======
4444

45+
As of Spring Framework 6.1, there is also special treatment of `CompletableFuture`
46+
(and general `Future`) return values, triggering a rollback for such a handle if it
47+
was exceptionally completed at the time of being returned from the original method.
48+
This is intended for `@Async` methods where the actual method implementation may
49+
need to comply with a `CompletableFuture` signature (auto-adapted to an actual
50+
asynchronous handle for a call to the proxy by `@Async` processing at runtime),
51+
preferring exposure in the returned handle rather than rethrowing an exception:
52+
53+
[tabs]
54+
======
55+
Java::
56+
+
57+
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
58+
----
59+
@Transactional @Async
60+
public CompletableFuture<String> myTransactionalMethod() {
61+
try {
62+
return CompletableFuture.completedFuture(delegate.myDataAccessOperation());
63+
}
64+
catch (DataAccessException ex) {
65+
return CompletableFuture.failedFuture(ex);
66+
}
67+
}
68+
----
69+
======
70+
4571
Checked exceptions that are thrown from a transactional method do not result in a rollback
4672
in the default configuration. You can configure exactly which `Exception` types mark a
4773
transaction for rollback, including checked exceptions by specifying _rollback rules_.

framework-docs/modules/ROOT/pages/testing/spring-mvc-test-framework/server-setup-options.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ a mock service with Mockito:
111111
[source,xml,indent=0,subs="verbatim,quotes"]
112112
----
113113
<bean id="accountService" class="org.mockito.Mockito" factory-method="mock">
114-
<constructor-arg value="org.example.AccountService"/>
114+
<constructor-arg type="java.lang.Class" value="org.example.AccountService"/>
115+
<constructor-arg type="java.lang.String" value="accountService"/>
115116
</bean>
116117
----
117118

spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,7 @@ public void addAdvisors(Collection<Advisor> advisors) {
369369
private void validateIntroductionAdvisor(IntroductionAdvisor advisor) {
370370
advisor.validateInterfaces();
371371
// If the advisor passed validation, we can make the change.
372-
Class<?>[] ifcs = advisor.getInterfaces();
373-
for (Class<?> ifc : ifcs) {
372+
for (Class<?> ifc : advisor.getInterfaces()) {
374373
addInterface(ifc);
375374
}
376375
}

spring-beans/src/main/java/org/springframework/beans/factory/support/RegisteredBean.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
* In the case of inner-beans, the bean name may have been generated.
4444
*
4545
* @author Phillip Webb
46+
* @author Stephane Nicoll
47+
* @author Juergen Hoeller
4648
* @since 6.0
4749
*/
4850
public final class RegisteredBean {
@@ -262,9 +264,11 @@ public String toString() {
262264

263265
/**
264266
* Descriptor for how a bean should be instantiated. While the {@code targetClass}
265-
* is usually the declaring class of the {@code executable}, there are cases
266-
* where retaining the actual concrete type is necessary.
267-
* @param executable the {@link Executable} to invoke
267+
* is usually the declaring class of the {@code executable} (in case of a constructor
268+
* or a locally declared factory method), there are cases where retaining the actual
269+
* concrete class is necessary (e.g. for an inherited factory method).
270+
* @param executable the {@link Executable} ({@link java.lang.reflect.Constructor}
271+
* or {@link java.lang.reflect.Method}) to invoke
268272
* @param targetClass the target {@link Class} of the executable
269273
* @since 6.1.7
270274
*/

0 commit comments

Comments
 (0)