@@ -193,47 +193,39 @@ Kotlin::
193
193
======
194
194
195
195
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.
199
199
200
200
[[transaction-declarative-annotations-method-visibility]]
201
- .Method visibility and `@Transactional`
201
+ .Method visibility and `@Transactional` in proxy mode
202
202
[NOTE]
203
203
====
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`:
217
212
218
213
[source,java,indent=0,subs="verbatim,quotes"]
219
214
----
220
215
/**
221
216
* 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.
226
218
* @see ProxyTransactionManagementConfiguration#transactionAttributeSource()
227
219
*/
228
220
@Bean
229
221
TransactionAttributeSource transactionAttributeSource() {
230
- return new AnnotationTransactionAttributeSource(false );
222
+ return new AnnotationTransactionAttributeSource(true );
231
223
}
232
224
----
233
225
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.
237
229
====
238
230
239
231
You can apply the `@Transactional` annotation to an interface definition, a method
@@ -374,7 +366,6 @@ Kotlin::
374
366
----
375
367
======
376
368
377
-
378
369
[[transaction-declarative-attransactional-settings]]
379
370
== `@Transactional` Settings
380
371
0 commit comments