我想知道这是否可能。这是我的第一个问题,如果我不完全遵守协议,请耐心等待。我可以使用事务模板回滚我的事务。但现在我要做的是在标记为@before 的方法中保存一个状态,然后在@after 方法中将其回滚。
例如这是我以前的:
_transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus transactionStatus)
{
Object transactionStatusSavepoint = transactionStatus.createSavepoint();
//do some work
transactionStatus.rollbackToSavepoint(transactionStatusSavepoint);
}
});
这一切都很好。现在我想这样做:
@Before
public void beforeTest() {
_template.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
_transactionStatusSavepoint = _transactionStatus.createSavepoint();
}
});
@Test
public void foo(){//do some stuff}
@After
public void afterTest() {
_transactionStatus.rollbackToSavepoint(_transactionStatusSavepoint);
}
如果您不明白或想详细说明,请告诉我。提前致谢!