Spring 手動提交事務

https://www.cnblogs.com/banning/p/6346669.htmlhtml

 

@Resource(name="transactionManager")
private DataSourceTransactionManager transactionManager;htm

DefaultTransactionDefinition transDefinition = new DefaultTransactionDefinition();
//開啓新事物
transDefinition.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionStatus transStatus = transactionManager.getTransaction(transDefinition);
try {
    //TODO
    transactionManager.commit(transStatus);
} catch (Exception e) {
    transactionManager.rollback(transStatus);
}blog

相關文章
相關標籤/搜索