diff --git a/spring-framework-reference/src/transaction.xml b/spring-framework-reference/src/transaction.xml index 058403586c0..65af86a9d78 100644 --- a/spring-framework-reference/src/transaction.xml +++ b/spring-framework-reference/src/transaction.xml @@ -1648,6 +1648,17 @@ public class DefaultFooService implements FooService { + + value + + String + + + Optional qualifier specifying the transaction manager to be used. + + + propagation @@ -1741,6 +1752,81 @@ public class DefaultFooService implements FooService { the name of the transaction would be: com.foo.BusinessService.handlePayment. + +
+ Multiple Transaction Managers with <interfacename>@Transactional</interfacename> + + Most Spring applications only need a single transaction manager, but there may be situations + where you want multiple independent transaction managers in a single application. + The value attribute of the @Transactional annotation can + be used to optionally specify the identity of the PlatformTransactionManager + to be used. This can either be the bean name or the qualifier value of the transaction manager bean. + For example, using the qualifier notation, the following Java code + + public class TransactionalService { + + @Transactional("order") + public void setSomething(String name) { ... } + + @Transactional("account") + public void doSomething() { ... } + } + + could be combined with the following transaction manager bean declarations in the application context. + + + + ... + + + + + ... + + +]]> + + In this case, the two methods on TransactionalService will run under separate + transaction managers, differentiated by the "order" and "account" qualifiers. + The default <tx:annotation-driven> target bean name transactionManager will + still be used if no specifically qualified PlatformTransactionManager bean is found. + +
+
+ Custom shortcut annotations + + If you find you are repeatedly using the same attributes with @Transactional + on many different methods, then Spring's meta-annotation support allows you to define custom shortcut + annotations for your specific use cases. For example, defining the following annotations + + @Target({ElementType.METHOD, ElementType.TYPE}) + @Retention(RetentionPolicy.RUNTIME) + @Transactional("order") + public @interface OrderTx { + } + + @Target({ElementType.METHOD, ElementType.TYPE}) + @Retention(RetentionPolicy.RUNTIME) + @Transactional("account") + public @interface AccountTx { + } + + allows us to write the example from the previous section as + + public class TransactionalService { + + @OrderTx + public void setSomething(String name) { ... } + + @AccountTx + public void doSomething() { ... } + } + + Here we have used the syntax to define the transaction manager qualifier, but could also have + included propagation behavior, rollback rules, timeouts etc. + +