Browse Source

Revise note on non-public transactional methods for 6.0

Closes gh-31057
See gh-25582
pull/31496/head
Juergen Hoeller 2 years ago
parent
commit
c8a4026512
  1. 43
      framework-docs/modules/ROOT/pages/data-access/transaction/declarative/annotations.adoc

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

@ -193,47 +193,39 @@ Kotlin::
====== ======
Note that there are special considerations for the returned `Publisher` with regards to Note that there are special considerations for the returned `Publisher` with regards to
Reactive Streams cancellation signals. See the xref:data-access/transaction/programmatic.adoc#tx-prog-operator-cancel[Cancel Signals] section under Reactive Streams cancellation signals. See the
"Using the TransactionalOperator" for more details. xref:data-access/transaction/programmatic.adoc#tx-prog-operator-cancel[Cancel Signals]
section under "Using the TransactionalOperator" for more details.
[[transaction-declarative-annotations-method-visibility]] [[transaction-declarative-annotations-method-visibility]]
.Method visibility and `@Transactional` .Method visibility and `@Transactional` in proxy mode
[NOTE] [NOTE]
==== ====
When you use transactional proxies with Spring's standard configuration, you should apply The `@Transactional` annotation is typically used on methods with `public` visibility.
the `@Transactional` annotation only to methods with `public` visibility. If you do As of 6.0, `protected` or package-visible methods can also be made transactional for
annotate `protected`, `private`, or package-visible methods with the `@Transactional` class-based proxies by default. Note that transactional methods in interface-based
annotation, no error is raised, but the annotated method does not exhibit the configured proxies must always be `public` and defined in the proxied interface. For both kinds
transactional settings. If you need to annotate non-public methods, consider the tip in of proxies, only external method calls coming in through the proxy are intercepted.
the following paragraph for class-based proxies or consider using AspectJ compile-time or
load-time weaving (described later). If you prefer consistent treatment of method visibility across the different kinds of
proxies (which was the default up until 5.3), consider specifying `publicMethodsOnly`:
When using `@EnableTransactionManagement` in a `@Configuration` class, `protected` or
package-visible methods can also be made transactional for class-based proxies by
registering a custom `transactionAttributeSource` bean like in the following example.
Note, however, that transactional methods in interface-based proxies must always be
`public` and defined in the proxied interface.
[source,java,indent=0,subs="verbatim,quotes"] [source,java,indent=0,subs="verbatim,quotes"]
---- ----
/** /**
* Register a custom AnnotationTransactionAttributeSource with the * Register a custom AnnotationTransactionAttributeSource with the
* publicMethodsOnly flag set to false to enable support for * publicMethodsOnly flag set to true to consistently ignore non-public methods.
* protected and package-private @Transactional methods in
* class-based proxies.
*
* @see ProxyTransactionManagementConfiguration#transactionAttributeSource() * @see ProxyTransactionManagementConfiguration#transactionAttributeSource()
*/ */
@Bean @Bean
TransactionAttributeSource transactionAttributeSource() { TransactionAttributeSource transactionAttributeSource() {
return new AnnotationTransactionAttributeSource(false); return new AnnotationTransactionAttributeSource(true);
} }
---- ----
The _Spring TestContext Framework_ supports non-private `@Transactional` test methods by The _Spring TestContext Framework_ supports non-private `@Transactional` test methods
default. See xref:testing/testcontext-framework/tx.adoc[Transaction Management] in the testing by default as well. See xref:testing/testcontext-framework/tx.adoc[Transaction Management]
chapter for examples. in the testing chapter for examples.
==== ====
You can apply the `@Transactional` annotation to an interface definition, a method You can apply the `@Transactional` annotation to an interface definition, a method
@ -374,7 +366,6 @@ Kotlin::
---- ----
====== ======
[[transaction-declarative-attransactional-settings]] [[transaction-declarative-attransactional-settings]]
== `@Transactional` Settings == `@Transactional` Settings

Loading…
Cancel
Save