且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

具有@Transactional批注的多个事务管理器

更新时间:2023-11-22 19:19:40

可以的快捷方式. (这些可以在类或方法级别使用)

There is the possibility to create your own annotations as shortcuts for @Transactional(value="tx1"). (These can be used at class or method level)

来自参考文档:

例如,定义以下注释

@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() { ... }
  }