@Transactional 注释的替代方案 [英] Alternative of @Transactional annotation
本文介绍了@Transactional 注释的替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
spring 回滚事务除了@Transactional 注释之外还有什么选择.我已经使用了这个注释,但我想要我可以在 catch 块中回滚事务的方式.有什么办法吗?
What is the alternative of rollback transaction in spring except @Transactional annotation. I have used this annotation but i want the way by which i can rollback transaction in catch block. Is there any way?
提前谢谢.
推荐答案
这是一个草稿:
public class SomeService implements SomeInterface {
private SomeDao thisDaoWrapsJdbcTemplate;
private PlatformTransactionManager transactionManager;
public void setTransactionManager( PlatformTransactionManager transactionManager ) {
this.transactionManager = transactionManager;
}
public void doBusiness( Business: business ) {
TransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction( def );
try {
// do business here
Money money = Money.LOTS_OF
...
// wire the money in..
thisDaoWrapsJdbcTemplate.depositLotsOfMoney( money )
transactionManager.commit( status );
} catch ( DataAccessException dae ) {
transactionManager.rollback( status );
throw dae;
}
return;
}
这篇关于@Transactional 注释的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文