@BeforeTransaction
@BeforeTransaction
表示应在启动事务之前运行带注释的 void
方法,对于已使用 Spring 的 @Transactional
注解配置为在事务中运行的测试方法。@BeforeTransaction
方法不需要为 public
,并且可以在基于 Java 8 的接口默认方法中声明。
@BeforeTransaction
indicates that the annotated void
method should be run before a
transaction is started, for test methods that have been configured to run within a
transaction by using Spring’s @Transactional
annotation. @BeforeTransaction
methods
are not required to be public
and may be declared on Java 8-based interface default
methods.
以下示例展示了如何使用 @BeforeTransaction
注解:
The following example shows how to use the @BeforeTransaction
annotation:
- Java
-
@BeforeTransaction (1) void beforeTransaction() { // logic to be run before a transaction is started }
1 | Run this method before a transaction.
|
2 | Run this method before a transaction. |