更新时间: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() { ... }
}