Skip to content

Commit c8a4026

Browse files
committed
Revise note on non-public transactional methods for 6.0
Closes gh-31057 See gh-25582
1 parent 2111bf9 commit c8a4026

File tree

1 file changed

+17
-26
lines changed
  • framework-docs/modules/ROOT/pages/data-access/transaction/declarative

1 file changed

+17
-26
lines changed

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

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -193,47 +193,39 @@ Kotlin::
193193
======
194194

195195
Note that there are special considerations for the returned `Publisher` with regards to
196-
Reactive Streams cancellation signals. See the xref:data-access/transaction/programmatic.adoc#tx-prog-operator-cancel[Cancel Signals] section under
197-
"Using the TransactionalOperator" for more details.
198-
196+
Reactive Streams cancellation signals. See the
197+
xref:data-access/transaction/programmatic.adoc#tx-prog-operator-cancel[Cancel Signals]
198+
section under "Using the TransactionalOperator" for more details.
199199

200200
[[transaction-declarative-annotations-method-visibility]]
201-
.Method visibility and `@Transactional`
201+
.Method visibility and `@Transactional` in proxy mode
202202
[NOTE]
203203
====
204-
When you use transactional proxies with Spring's standard configuration, you should apply
205-
the `@Transactional` annotation only to methods with `public` visibility. If you do
206-
annotate `protected`, `private`, or package-visible methods with the `@Transactional`
207-
annotation, no error is raised, but the annotated method does not exhibit the configured
208-
transactional settings. If you need to annotate non-public methods, consider the tip in
209-
the following paragraph for class-based proxies or consider using AspectJ compile-time or
210-
load-time weaving (described later).
211-
212-
When using `@EnableTransactionManagement` in a `@Configuration` class, `protected` or
213-
package-visible methods can also be made transactional for class-based proxies by
214-
registering a custom `transactionAttributeSource` bean like in the following example.
215-
Note, however, that transactional methods in interface-based proxies must always be
216-
`public` and defined in the proxied interface.
204+
The `@Transactional` annotation is typically used on methods with `public` visibility.
205+
As of 6.0, `protected` or package-visible methods can also be made transactional for
206+
class-based proxies by default. Note that transactional methods in interface-based
207+
proxies must always be `public` and defined in the proxied interface. For both kinds
208+
of proxies, only external method calls coming in through the proxy are intercepted.
209+
210+
If you prefer consistent treatment of method visibility across the different kinds of
211+
proxies (which was the default up until 5.3), consider specifying `publicMethodsOnly`:
217212
218213
[source,java,indent=0,subs="verbatim,quotes"]
219214
----
220215
/**
221216
* Register a custom AnnotationTransactionAttributeSource with the
222-
* publicMethodsOnly flag set to false to enable support for
223-
* protected and package-private @Transactional methods in
224-
* class-based proxies.
225-
*
217+
* publicMethodsOnly flag set to true to consistently ignore non-public methods.
226218
* @see ProxyTransactionManagementConfiguration#transactionAttributeSource()
227219
*/
228220
@Bean
229221
TransactionAttributeSource transactionAttributeSource() {
230-
return new AnnotationTransactionAttributeSource(false);
222+
return new AnnotationTransactionAttributeSource(true);
231223
}
232224
----
233225
234-
The _Spring TestContext Framework_ supports non-private `@Transactional` test methods by
235-
default. See xref:testing/testcontext-framework/tx.adoc[Transaction Management] in the testing
236-
chapter for examples.
226+
The _Spring TestContext Framework_ supports non-private `@Transactional` test methods
227+
by default as well. See xref:testing/testcontext-framework/tx.adoc[Transaction Management]
228+
in the testing chapter for examples.
237229
====
238230

239231
You can apply the `@Transactional` annotation to an interface definition, a method
@@ -374,7 +366,6 @@ Kotlin::
374366
----
375367
======
376368

377-
378369
[[transaction-declarative-attransactional-settings]]
379370
== `@Transactional` Settings
380371

0 commit comments

Comments
 (0)